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

Why won't this GUI button work?

Expanding on my PM script, I made a button in a ScreenGUI that changes whether a person can received PMs or not. However, when the button is clicked, the value does not change and neither does the text. The output tells me nothing. Here is the script:

while true do
	if game.Players.LocalPlayer:FindFirstChild("PM") == nil then
		f = Instance.new("BoolValue")
		f.Name = "PM"
		f.Value = true		
		f.Parent = game.Players.LocalPlayer
	end
	wait(0.2)
end

function onClick()
	print ("hi")
	if script.Parent.on.Value == false then
		script.Parent.on.Value = true
		game.Players.LocalPlayer.PM.Value = true
		script.Parent.Text = "PMs Allowed"
	elseif script.Parent.on.Value == true then
		script.Parent.on.Value = false
		game.Players.LocalPlayer.PM.Value = false
		script.Parent.Text = "PMs Disallowed"
	end
end

script.Parent.MouseButton1Down:connect(onClick)

Can anyone help? The print doesn't show in the output either.

1 answer

now, I'm not sure if this'll fix it, but it's easier to use one line for a function

while true do
    if game.Players.LocalPlayer:FindFirstChild("PM") == nil then
        f = Instance.new("BoolValue")
        f.Name = "PM"
        f.Value = true      
        f.Parent = game.Players.LocalPlayer
    end
    wait(0.2)
end

script.Parent.MouseButton1Down:connect(function() --Instead of having 2 lines, we can make it one
    print ("hi")
    if script.Parent.on.Value == false then
        script.Parent.on.Value = true
        game.Players.LocalPlayer.PM.Value = true
        script.Parent.Text = "PMs Allowed"
    elseif script.Parent.on.Value == true then
        script.Parent.on.Value = false
        game.Players.LocalPlayer.PM.Value = false
        script.Parent.Text = "PMs Disallowed"
    end
end)

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