So i've made a script that puts 1 boolean inside the player for each trophy.What i'm trying to do is make it so that when a player clicks on the trophy it changes the value inside the player from true to false so that i can later store it with data service after he leaves. However this script doesn't output any errors and it also doesn't change the boolean from false to true instead i can click and it adds +1 to my trophies over and over.I've also inserted print to see if the script fires off completely and it does.
Thanks for your time
[script.Parent.ClickDetector.MouseClick:connect(function(hit) local player = hit if player ~= nil then local stats = player:WaitForChild("leaderstats") local trophies = stats:WaitForChild("Trophies") local humanoid = player.Character:WaitForChild("Humanoid") local p = player:FindFirstChild("Trophy1") print 'y' if p ~= nil and p == false then p.Value = true end print 'a' if (humanoid.Health > 0) then trophies.Value = trophies.Value + 1 end end end)
For the if statement, you just checked if the character was alive, you never checked the trophy, so if the character was alive and clicked then they would get +1 trophies and it had nothing to do with the trophy type, the below code should work.
script.Parent.ClickDetector.MouseClick:connect(function(hit) local player = hit if player ~= nil then local stats = player:WaitForChild("leaderstats") local trophies = stats:WaitForChild("Trophies") local humanoid = player.Character:WaitForChild("Humanoid") local p = player:FindFirstChild("Trophy1") if p ~= nil and p == false then p.Value = true trophies.Value = trophies.Value + 1 end end end)