What solutions have you tried so far? So luis a web dev helped alot but i forgot to add something else
Im making a game when you punch something you get Resources and if you get resources you can get upgrades and if you get upgrades you get 2x damage then normal im trying to script it but im very new to scripting so yea.
local click = script.Parent.ClickDetector
local value = script.Parent.Value
wait(.00000000000000001)
local damage = game.Players:GetChildren("Value")
click.MouseClick:Connect(function(player)
local resources = player:WaitForChild("leaderstats"):WaitForChild("Resources")
value.Value += 1
if damage.Value >= 1 then
value.Value += 1
if value.Value >= 5 then
script.Parent.Transparency = 1
script.Parent.CanCollide = false
if value.Value == 5 then
script.Parent.Transparency = 1
script.Parent.CanCollide = false
resources.Value += 1
wait(10)
script.Parent.Transparency = 0
script.Parent.CanCollide = false
value.Value = 0
end
end
end
end)
wait(.00000000000000001) is such an infinitesimally small number it shouldn’t be there. :GetChildren() also accepts no parameters, perhaps you meant game.Players:WaitForChild("Value")?
You’d need to address the architecture of the game to achieve what you want. Each player should house their own damage value; it looks like you’re referencing a singular value for everyone. Not sure what script.Parent is referencing but it looks like a tree you punch? Each tree should be handled by a script/module script in ServerScriptService, and have that script handle the players’ damage and resources, to keep such values from being exposed to exploiters.
local part = script.Parent
local click = part.ClickDetector
local value = part.Value
local players = game:GetService("Players")
local damage = players:GetChildren("Value") --Does this even exist? Parenting instances to the players service is unusual.
click.MouseClick:Connect(function(player)
value.Value += 1
if damage.Value >= 1 then
value.Value += 1
end
if value.Value >= 5 then
value.Value = 0
part.Transparency = 1
part.CanCollide = false
player.leaderstats.Resources.Value += 1
task.wait(10)
part.Transparency = 0
part.CanCollide = true
end
end)
I just realized it’s wrong anyway, you don’t pass arguments to “:GetChildren()” since it just returns an array of the instances children. Here’s the script with that part removed.
local part = script.Parent
local click = part.ClickDetector
local value = part.Value
click.MouseClick:Connect(function(player)
value.Value += 1
if value.Value >= 5 then
value.Value = 0
part.Transparency = 1
part.CanCollide = false
player.leaderstats.Resources.Value += 1
task.wait(10)
part.Transparency = 0
part.CanCollide = true
end
end)
Do you know how to put damage like when a player upgrades with resources then it gives like 2 damage to the object and im sorry if im asking for to much