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

change a variable on a localscript after touching a button?

Asked by 3 years ago

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
0
where is the variable you want to change? tracer_r 19 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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)
Ad

Answer this question