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

I made a toggle script and I don't know the parameter given by the event so it's giving an error?

Asked by 5 years ago

I'm making a door that allows only the owner. The players can go through, if the owner toggles that they can go. The script below is the toggle script. I'm suspecting that the parameter is wrong. So the question is, what parameter does the event MouseButtonClick provide in the function?

01print("Hello world!")
02local TrueColor= game.Workspace.Model.Values.ValidColor
03local Allow= game.Workspace.Model.Values.IsTheDoorUnlocked
04local FalseColor= game.Workspace.Model.Values.InvalidColor
05local toggle= script.Parent
06 
07toggle.ClickDetector.MouseClick:Connect(function(whoClicked)
08    local player= game.Players:GetPlayerFromCharacter(whoClicked)
09    if player.UserId== 263105732 then
10        Allow.Value= not Allow.Value
11        if Allow.Value== false then
12            toggle.BrickColor= FalseColor.Value
13        else
14            toggle.BrickColor= TrueColor.Value
15        end
16    end
17end)
1
The MouseClick event's parameter provides the player that clicked the ClickDetector Sorukan 240 — 5y

1 answer

Log in to vote
1
Answered by
Sorukan 240 Moderation Voter
5 years ago
Edited 5 years ago
01print("Hello world!")
02local TrueColor= game.Workspace.Model.Values.ValidColor
03local Allow= game.Workspace.Model.Values.IsTheDoorUnlocked
04local FalseColor= game.Workspace.Model.Values.InvalidColor
05local toggle= script.Parent
06 
07toggle.ClickDetector.MouseClick:Connect(function(player)
08    if player.UserId == 263105732 then
09        Allow.Value = not Allow.Value
10        if Allow.Value== false then
11            toggle.BrickColor= FalseColor.Value
12        else
13            toggle.BrickColor= TrueColor.Value
14        end
15    end
16end)

The parameter IS the player who clicked it so there's no reason to use GetPlayerFromCharacter. I haven't tested this yet but it should work

1
theres a space in "toggle.BrickColo r= TrueColor.Value" RAFA1608 543 — 5y
Ad

Answer this question