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

change a variable on a localscript after touching a button?

Hello! i would like it so that when a player steps on a button (using touch) it would change a variable in a localscript for that player. iv'e used binable events but that did it for all the players and not the one that was on the button. here is the touch code i am using for the button

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
			--set variable to true
		end
	end
end)

here is the player code

hasPassengers = false

1 comment

0

where is the variable you want to change?

1 answer

Simply fire a Remote Event:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if plr then
          game.ReplicatedStorage.PlaceHolderforyourEvent:FireClient(plr)
        end
    end
end)

Inside Player:

hasPassengers = false
 game.ReplicatedStorage.PlaceHolderforyourEvent.OnClientEvent:Connect(function()
hasPassengers = true
end)

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