Roblox leaderstat only updates once - roblox

I'm trying to reward the player with exp every time they the punch a damageable object (punching bag, dummies, etc) Whenever the play punches something, it updates the exp leaderstat only once, does anyone know what i'm doing wrong?
My Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
script.Parent.Touched:Connect(function(hit)
local Char = hit.parent
local Hum = Char:FindFirstChild("Humanoid")
if Hum and Char.Name ~= script.Parent.Parent.Name then
local Indicator = require(game.ReplicatedStorage.DamageIndicator)
local Player = script.Parent.Parent
local LocalPlayer = game.Players:GetPlayerFromCharacter(Player)
local Exp = LocalPlayer.leaderstats.Experience.Value
Hum:TakeDamage(script.Dmg.Value)
Indicator.DamageActivate(script.Dmg.Value, hit)
Exp = Exp + 15
LocalPlayer.PlayerGui.UI.Experience.ExpBar.Size = UDim2.new((Exp / 100) * 0, 0, 0.02, 0)
LocalPlayer.PlayerGui.UI.Experience.ExpBackground.ExpAmt.Text = Exp.."/100"
script.Disabled = true
end
end)

You're having the same issue as this guy.
When you create a variable based on a NumberValue's Value, you are storing a copy of the value, not a reference to it. If you want to update the value, you need to manually assign it.
local Exp = LocalPlayer.leaderstats.Experience
Exp.Value = Exp.Value + 15
local ExpGui = LocalPlayer.PlayerGui.UI.Experience
ExpGui.ExpBar.Size = UDim2.new((Exp.Value / 100) * 0, 0, 0.02, 0)
ExpGui.ExpBackground.ExpAmt.Text = tostring(Exp.Value) .. "/100"

Related

ServerScriptService.Size:4: attempt to index nil with 'Humanoid'

Cant figure out what the problem is
while wait(.5) do
local children = game.Players:GetChildren("Humanoid")
for i = 1, #children do
local hum = children[i] .Character.Humanoid
hum.HeadScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.BodyHeightScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.BodyWidthScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.BodyDepthScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.WalkSpeed = children[i].leaderstats.Points.Value/3.12
hum.JumpPower = children[i].leaderstats.Points.Value
hum.MaxHealth = children[i].leaderstats.Points.Value+25
end
end
was trying to get a simple size script to work.
The attempt to index nil with Humanoid error is telling you that the object that you are trying to grab the Humanoid out of doesn't exist. This line specifically :
local hum = children[i].Character.Humanoid
When a player joins the game, there is an indeterminate amount of time before their character model actually spawns into the world. So between when they join and when their character spawns, the Player.Character property is nil.
Your code does not handle the possibility that the character model is nil, and you are trying to access the humanoid immediately.
A safer approach is not to use a loop, but to observe changes to the leaderstats values and react to those changes. So in your code that creates your leaderstats objects, do something like this :
local Players = game:GetService("Players")
local function updateCharacter(hum : Humanoid, points : number)
local bodyScale = (points / 50) + 1
local walkSpeed = points / 3.12
local jump = points
local health = points + 25
hum.HeadScale.Value = bodyScale
hum.BodyHeightScale.Value = bodyScale
hum.BodyWidthScale.Value = bodyScale
hum.BodyDepthScale.Value = bodyScale
hum.WalkSpeed = walkSpeed
hum.JumpPower = jump
hum.MaxHealth = health
end
Players.PlayerAdded:Connect(function(player)
-- when a player joins the game, give them a leaderstats folder
local leaderstatsFolder = Instance.new("Folder")
leaderstatsFolder.Name = "leaderstats"
local pointsValue = Instance.new("IntValue", leaderstats)
pointsValue.Name = "Points"
pointsValue.Value = 0 -- or load from dataStores
leaderstatsFolder.Parent = player
-- listen for changes to the points and resize the character
pointsValue.Changed:Connect(function(newValue)
-- escape if the character doesn't exist
local character = player.Character
if character then
updateCharacter(character.Humanoid, newValue)
end
end)
-- when the character model spawns into the world, update it immediately with the player's point size
player.CharacterAdded:Connect(function(character)
updateCharacter(character.Humanoid, pointsValue.Value)
end)
end)

How to get SubtractAsync to fully slice off piece of the part

I'm trying to slice a part of this part, so that it matches the bottom part, and the method I'm trying is SubtractAsync.
When I do it however, the part gets sliced, but not so that the remaining part gets removed. Here's what I mean:
How do I edit my code to slice off the piece of the part?
My code:
local Brick = workspace.Brick
local Stack = Brick:Clone()
local TS = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, math.huge, true)
Stack.Position = Vector3.new(Brick.Position.X, Brick.Position.Y + Brick.Size.Y, Brick.Position.Z - 55)
local tween = TS:Create(Stack, tweenInfo, {Position = Vector3.new(Stack.Position.X, Stack.Position.Y, Stack.Position.Z + (55 * 2))})
Stack.Parent = workspace
tween:Play()
game.ReplicatedStorage.PlaceDown.OnServerEvent:Connect(function()
tween:Pause()
local PartA = Instance.new("Part")
local PartB = Instance.new("Part")
PartA.Transparency = 1
PartB.Transparency = 1
PartA.Parent = workspace
PartB.Parent = workspace
PartA.Orientation = Vector3.new(-90, 0, 0)
PartB.Orientation = Vector3.new(-90, 0, 0)
PartA.Size = Vector3.new(15, 0.051, 15)
PartB.Size = Vector3.new(15, 0.051, 15)
PartA.Position = Vector3.new(Brick.Position.X, Brick.Position.Y + 2.5, Brick.Position.Z - (Brick.Size.Z/2))
PartB.Position = Vector3.new(Brick.Position.X, Brick.Position.Y + 2.5, Brick.Position.Z + (Brick.Size.Z/2))
PartA.Anchored = true
PartB.Anchored = true
local SlicedStack = Stack:SubtractAsync({PartA, PartB})
SlicedStack.Position = Stack.Position
SlicedStack.Parent = workspace
Stack:Destroy()
PartA:Destroy()
PartB:Destroy()
end)

Infinite leaderstat Abbreviating

I own a simulator with 0 active that has Clicks. When I upgrade too much, my clicks get negative amount of clicks at a few quintillions (10^18), abbreviations work until decillions. (10^33). How do I make that clicks will not turn negative or something else wrong will happen with their value when I reach over a few quintillions?
Leaderstats Script (game.Workspace):
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("IntValue",plr)
leaderstats.Name = "leaderstats"
local Clicks = Instance.new("IntValue",leaderstats)
Clicks.Name = "Clicks"
local Power = Instance.new("IntValue",leaderstats)
Power.Name = "Power"
Power.Value = 1
local SC = Instance.new("IntValue",leaderstats)
SC.Name = "SuperClicks"
local MC = Instance.new("IntValue",leaderstats)
MC.Name = "MegaClicks"
local SCC = Instance.new("IntValue",leaderstats)
SCC.Name = "SuperClicksChance"
SCC.Value = 10
local MCC = Instance.new("IntValue",leaderstats)
MCC.Name = "MegaClicksChance"
MCC.Value = 1
local ODMG = Instance.new("IntValue",leaderstats)
ODMG.Name = "OreDamage"
ODMG.Value = 1
local SP = Instance.new("IntValue",leaderstats)
SP.Name = "SuperPower"
SP.Value = 1
local MP = Instance.new("IntValue",leaderstats)
MP.Name = "MegaPower"
MP.Value = 1
local Gems = Instance.new("IntValue",leaderstats)
Gems.Name = "Gems"
local OD = Instance.new("IntValue",leaderstats)
OD.Name = "OreDamage"
OD.Value = 1
if Clicks.Value >= (9 * (10 ^ 17)) then
Clicks.Value = 0
Power.Value = 1
end
end)
Everything works, but I also made that if I get 900 quadrillion clicks, my power and clicks will reset. But I don't want that. I want atleast to know how to create a stat with amount of zeros in my clicks. If it will work, I will make that in GUI Counter will be shown like this: 10^x (x = amount of zeros)
Also, if you want to try my simulator, here's the link:
Click Simulator Beta 0.31

Roblox Studio Error: Expected ')' (to close '(' at column 18), got '='

I am trying to make a door move to a new position using the tween service. The problem is that I keep getting the error, Expected ')' (to close '(' at column 18), got '=', and I don't know why. It highlights the "=" next to "Position" on line 21 in red.
local service = game:GetService("TweenService")
local cupboard1 = game.Workspace.Door1
local cupboard2 = game.Workspace.Door2
local cupboard3 = game.Workspace.Door3
local cupboard4 = game.Workspace.Door4
local handle1 = game.Workspace.Handle1
local handle2 = game.Workspace.Handle2
local handle3 = game.Workspace.Handle3
local handle4 = game.Workspace.Handle4
local info = TweenInfo.new(2)
if state == true then
game.Workspace.Handle1.ClickDetector.MouseClick:connect(function()
local state = false
local change = (Position = Vector3.new(61.831, 4.997, 68.415)) -- door
local change1 = (Position = Vector3.new(63.401, 5.416, 67.89)) -- handle
local change2 = (Orientation = Vector3.new(0, 90, 0)) -- handle
local change3 = (Orientation = Vector3.new(0, 90, 0)) -- door
local tween = service:Create(cupboard1, info, change)
tween:Play()
local tween1 = service:Create(handle1, info, change1)
tween1:Play()
local tween2 = service:Create(handle1, info, change2)
tween2:Play()
local tween3 = service:Create(cupboard1, info, change3)
tween3:Play()
end)
end
if state == false then
game.Workspace.Handle1.ClickDetector.MouseClick:connect(function()
local state = true
local change = (Position = Vector3.new(58.112, 4.997, 66.588)) -- door
local change1 = (Position = Vector3.new(56.631, 5.416, 65.849)) -- handle
local change2 = (Orientation = Vector3.new(0, -135, 0)) -- handle
local change3 = (Orientation = Vector3.new(0, -135, 0)) -- door
local tween = service:Create(cupboard1, info, change)
tween:Play()
local tween1 = service:Create(handle1, info, change1)
tween1:Play()
local tween2 = service:Create(handle1, info, change2)
tween2:Play()
local tween3 = service:Create(cupboard1, info, change3)
tween3:Play()
end)
end
I've tried changing "=" to "==" but it gives me a warning saying Position and Orientation isn't defined.
You are trying to pass a table of changes into your tween. But when you use parenthesis, it is trying to evaluate the line, and this isn't valid lua.
Try changing your parentheses to curly brackets. This will properly assign the changes as a table, which you can pass to your tweens.
local change = { Position = Vector3.new(58.112, 4.997, 66.588)} -- door
local tween = service:Create(cupboard1, info, change)

How to animate (moving by default) and inanimate (make stationary on tap) colliding objects

Hey tired this new code to animate objects (here bubbles) and make them stationary using sprites. The code is as below,
local ui = require("ui")
local gameUI = require("gameUI")
local easingx = require("easingx")
require "sprite"
display.setStatusBar( display.HiddenStatusBar )
local physics = require("physics")
physics.start()
physics.setScale( 60 )
local backgroundPortrait = display.newImage( "sky.png", 0, 0 )
local backgroundLandscape = display.newImage( "sky.png", 80, 80 )
backgroundLandscape.isVisible = false
local disp = backgroundLandscape
local function selectBubble( event )
local tapped = event.target --event.target is how Corona points to the tapped bubble
if ( tapped.bubbleSelected == false ) then
local vx,vy = tapped:getLinearVelocity()
tapped.xVel = vx --stores the current velocity into bubble's "xVel" variable
tapped.yVel = vy --likewise for yVel
tapped:setLinearVelocity( 0,0 ) --set bubble's velocity to 0!
tapped.currentFrame = (3)
tapped.bubbleSelected = true
elseif ( tapped.bubbleSelected == true ) then
tapped:setLinearVelocity( tapped.xVel, tapped.yVel ) --read previous velocity and set
tapped.bubbleSelected = false
end
end
--BUBBLE1
local bubble1 = sprite.newSprite( spriteSet1 )
bubble1.x = 100
bubble1.y = 100
physics.addBody(bubble1, {bounce=0.04, filter = bubbleCollisionFilter})
bubble1:setLinearVelocity( 2, 4 )
bubble1:addEventListener( "tap", selectBubble )
bubble1.bubbleSelected = false
bubble1:prepare("bubble")
bubble1:play()
--BUBBLE2
local bubble2 = sprite.newSprite( spriteSet1 )
bubble2.x = 210
bubble2.y = 20
physics.addBody(bubble2, {bounce=0.05, filter = bubbleCollisionFilter})
bubble2:setLinearVelocity( 2, 4 )
bubble2:prepare("bubble")
bubble2:play()
--BUBBLE3
local bubble3 = sprite.newSprite( spriteSet1 )
bubble3.x = 100
bubble3.y = 17
physics.addBody(bubble3, {bounce=0.02, filter = bubbleCollisionFilter})
bubble1:setLinearVelocity( 1, 2 )
bubble3:prepare("bubble")
bubble3:play()
--BUBBLE4
local bubble4 = sprite.newSprite( spriteSet1 )
bubble4.x = 310
bubble4.y = 20
physics.addBody(bubble4, {bounce=0.4, filter = bubbleCollisionFilter})
bubble4:setLinearVelocity( 2, 4 )
bubble4:prepare("bubble")
bubble4:play()
The problem is firstly the code doesn't seem to work. Secondly though the bubble changes color on tap (this color is same for most). Yet, each bubble has a unique letter on it. How to get this to work. Please help.
It's hard to know what exactly you're asking because your question is pretty vague (what does "animate" mean? And what do you mean by "doesn't seem to work"? explain these terms because they can mean multiple things) but I think you want to set the physics bodies to "static" in the tap event listener. Refer here for what I'm talking about:
http://developer.anscamobile.com/reference/index/bodybodytype
So inside the selectBubble() function you would type something like tapped.bodyType="static"