Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i better formulate this so it changes the value of a bool inside the player who clicked it?

Asked by
Nogalo 148
7 years ago

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)

1 answer

Log in to vote
0
Answered by
INOOBE_YT 387 Moderation Voter
7 years ago

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)
0
the script doesn't work , it stops at the if statement Nogalo 148 — 7y
0
It's a click if a player character clicks it, just assuming that anything that clicked on it is a character is bad tbh LightModed 81 — 7y
Ad

Answer this question