Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

2 comments

0

the script doesn't work , it stops at the if statement

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

This discussion is preserved as it was. New answers, comments, and votes are closed.