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

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

Asked by
DYBB 8
4 years ago

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

Log in to vote
0
Answered by
compUcomp 417 Moderation Voter
4 years ago

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.

Ad

Answer this question