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

How would I change a value added into the player?

I'm trying to make a sort of armor system and am just trying to test it out but it doesn't work. Basically, it adds a bool value to the player called "HasArmor" if its true its supposed to change the max health of the player to 150.
My problem is that I made a button to try and test this out but it isn't working and keeps giving me this error Workspace.Button.ProximityPrompt.Script:3: attempt to index nil with 'FindFirstChild

Here is the code I have written


function givearmor()
	if script.Parent.Triggered then
	 game.Players.LocalPlayer:FindFirstChild("HasArmor")
		print("HasArmor was found!")
	end
end

script.Parent.Triggered:Connect(givearmor)

1 answer

game.Players.LocalPlayer is for local script to access the local player as suggested in the name.

Proximity Prompts already gives you the player that triggered it as the first argument, so your "givearmor" will need to expect an argument which would be the player that triggered it. It could look something like this:

function givearmor(player)
    if player:FindFirstChild("HasArmor") then
   
        print("HasArmor was found!")
-- other code you want to run if the player has "HasArmor" in them
    end
end

script.Parent.Triggered:Connect(givearmor)

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