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

GUI button not spawning a part?

Asked by 2 years ago

So I am making a tool that has a GUI appear each time the tool Is equipped and then disappear when the tool Is unequipped, when you click on the GUI It creates a ball that rolls around damaging and also turning people Into stone, the problem Is that for some reason the GUI doesn't spawn a ball

(Btw In order for the ability to work I used a RemoteEvent)

GUI button script (Local script):

local button = script.Parent
local RemoteEvent = script.Parent.Parent.Parent:WaitForChild("RemoteEvent")
local debounce = false

button.MouseButton1Click:Connect(function()
    if not debounce then
        debounce = true
        RemoteEvent:FireClient()
        wait(5)
        debounce = false
    end
end)

Ability script (Server script):

local Tool = script.Parent
local RemoteEvent = Tool.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function()
    local Ball = Instance.new("Part")
    local VectorForce = Instance.new("VectorForce")
    local Attachment = Instance.new("Attachment")

    Ball.Parent = game.Workspace
    VectorForce.Parent = Ball
    Attachment.Parent = Ball
    VectorForce.Attachment0 = Attachment
    VectorForce.Force = Vector3.new(120,0,0)
    Ball.Shape = Enum.PartType.Ball
    Ball.Position = script.Parent.Parent.Parent.Handle.Position
    Ball.Orientation = script.Parent.Parent.Parent.Handle.Orientation
    Ball.Size = Vector3.new(6.52, 6.52, 6.52)
    Ball.Touched:Connect(function(hit)
        local humanoid = hit.Parent:WaitForChild("Humanoid")
        if humanoid then
            local BigRock = Instance.new("Part")

            BigRock.Parent = humanoid.Parent.Torso
            BigRock.Position = humanoid.Parent.Torso
            BigRock.Anchored = true
            BigRock.Size = Vector3.new(10,10,10)
            BigRock.CanCollide = true
            wait(3)
            BigRock:Destroy()
        end
    end)
    wait(5)
    Ball:Destroy()
end)

Show GUI when the tool Is equipped and hide GUI when tool Unequipped(Local Script):

wait(1)
GUI = script.Parent.AbilityGUI
local Player = game.Players.LocalPlayer

script.Parent.Equipped:Connect(function()
    local GUIClone = GUI:Clone()
    GUIClone.Parent = Player.PlayerGui
    script.Parent.Unequipped:Connect(function()
        GUIClone:Destroy()
    end)
end)

1 answer

Log in to vote
0
Answered by
sngnn 274 Moderation Voter
2 years ago

:FireClient() is meant to be used in server scripts, to fire to a LocalScript. Your event is looking for :FireServer() instead, so you would change :FireClient() to :FireServer().

By the way, you should set the parent of the part last.

Ad

Answer this question