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

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

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?

print("Hello world!")
local TrueColor= game.Workspace.Model.Values.ValidColor
local Allow= game.Workspace.Model.Values.IsTheDoorUnlocked
local FalseColor= game.Workspace.Model.Values.InvalidColor
local toggle= script.Parent

toggle.ClickDetector.MouseClick:Connect(function(whoClicked)
	local player= game.Players:GetPlayerFromCharacter(whoClicked)
	if player.UserId== 263105732 then
		Allow.Value= not Allow.Value
		if Allow.Value== false then
			toggle.BrickColor= FalseColor.Value
		else
			toggle.BrickColor= TrueColor.Value
		end
	end
end)

1 comment

1

The MouseClick event's parameter provides the player that clicked the ClickDetector

1 answer

✓ Accepted answer
print("Hello world!")
local TrueColor= game.Workspace.Model.Values.ValidColor
local Allow= game.Workspace.Model.Values.IsTheDoorUnlocked
local FalseColor= game.Workspace.Model.Values.InvalidColor
local toggle= script.Parent

toggle.ClickDetector.MouseClick:Connect(function(player)
    if player.UserId == 263105732 then
        Allow.Value = not Allow.Value
        if Allow.Value== false then
            toggle.BrickColor= FalseColor.Value
        else
            toggle.BrickColor= TrueColor.Value
        end
    end
end)

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 comment

1

theres a space in "toggle.BrickColo r= TrueColor.Value"

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