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

Why won't this GUI button work?

Asked by
JJ_B 250 Moderation Voter
8 years ago

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

Log in to vote
0
Answered by
NotSoNorm 777 Moderation Voter
8 years ago

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

Answer this question