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

Script works perfectly fine, but doesn't do anything after I reset?

I'm using a script in SSS for a gui where once you click, it adds something to your character. Everything works, but it just doesn't do anything or print after I reset.

code:

game.Players.PlayerAdded:Connect(function(Player)

Player.CharacterAdded:connect(function()
local Button = Player.PlayerGui:WaitForChild("O1").main.EFrame.J2.TextButton
local vp = Player.PlayerGui:WaitForChild("O1").main.EFrame.J2.ViewportFrame
local Debounce = false
local Event = game:GetService("ReplicatedStorage"):WaitForChild("EventsFolder").ChangerEvent
local function lerp(start, goal, alpha)
    return start + alpha * (goal - start)
end
local mouseOver = false
Button.MouseButton1Click:Connect(function(hit)
    if Debounce == false then
        if Player and Player.Character.Humanoid.Health>=0 then
            Event:Fire(Player, Button.G1.Value) 
            Debounce = true
            wait(.5)
            Debounce = false
        end
    end
end)
end)

end)

1 answer

You cannot access the PlayerGui from the server. Instead, fire a RemoteEvent when the button is clicked and handle the action there. If you want, you can pass Button.G1.Value as a parameter to FireServer. Since your button only seems to be modifying the GUI, consider removing the RemoteEvents entirely and just manipulate the GUI on the client.

Also, line 15 should be Event:FireClient(Player, Button.G1.Value). :Fire is used for BindableEvents.

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