GUI's won't show

So I am trying to make some GUI’s pop up through an event that I can only use with a server script I.e. teleporting a player. So, I made three events, I, R, and O, and made it so that at the desired time they would fire and a local script would pick it up and open the GUI’s, but it does not work. There are no errors either.
Here is my code:

Server script

local char = game.Players:GetPlayerFromCharacter(script.Parent)
local part = char.Backpack.Handcuff.Handle
part.Touched:Connect(function(h)
    local hum = h.Parent:FindFirstChild("Humanoid")
    if not hum then return 
    elseif not hum:FindFirstChildOfClass("Animator") then local inst = Instance.new("Animator"); inst.Parent = hum end
    local animator = hum:WaitForChild("Animator")
    local animationTrack = animator:LoadAnimation(script.Animation)
    local R = game.ReplicatedStorage.R
    local I = game.ReplicatedStorage.I
    local O = game.ReplicatedStorage.O
    animationTrack:Play()
    O:FireClient()
    I.OnServerEvent:Connect(function()
	    hum.Torso.CFrame = CFrame.new(0.5, 4.65, 29.5)--where ever you wnat the arrested person to go
	    wait(1)--How long you want them to stay in prison for
	    hum.Torso.CFrame = CFrame.new(-0.75, 5.5, -0.75)--where ever you wnat the arrested person to go after they have been released from jail
    end)
    R.OnServerEvent:Connect(function()
	    animationTrack:Stop()
    end)
end)

local script:

local RButton = script.Parent.R
local IButton = script.Parent.I
local REvent = game.ReplicatedStorage.R
local IEvent = game.ReplicatedStorage.I
local OEvent = game.ReplicatedStorage.O
OEvent.OnClientEvent:Connect(function()
    RButton.Visible = true
    IButton.Visible = true
end)
RButton.MouseButton1Click:Connect(function()
    REvent:FireServer()
    RButton.Visible = false
    IButton.Visible = false
end)
IButton.MouseButton1Click:Connect(function()
    IEvent:FireServer()
    RButton.Visible = false
    IButton.Visible = false
end)
2 Likes

My brain

Couldn’t you just reference the Server Script inside the Tool itself? I don’t know why you seem to be overcomplicating the issue here

local Part = script.Parent
local R = game.ReplicatedStorage:WaitForChild("R")
local I = game.ReplicatedStorage:WaitForChild("I")
local O = game.ReplicatedStorage:WaitForChild("O")
local DB = false
local AnimationTrack

Part.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)

    if not DB and Player then
        DB = true
        local Humanoid = Hit.Parent.Humanoid

        AnimationTrack = Humanoid.Animator:LoadAnimation(script.Animation)
        AnimationTrack:Play()

        O:FireClient(Player) --FireClient requires a Player Object, I'm assuming you want it to be the target
    end
end)

I.OnServerEvent:Connect(function(Player)
    local Character = Player.Character

    Character.Torso.CFrame = CFrame.new(0.5, 4.65, 29.5)
    wait(1)
    Character.Torso.CFrame = CFrame.new(-0.75, 5.5, -0.75)
end)

R.OnServerEvent:Connect(function(Player)
    AnimationTrack:Stop()
end)

Because the tool will be given to police and when you replicate a tool into someone’s inventory it does not copy the script over too.

Why couldn’t you just clone the Tool inside a Service? Wouldn’t that be easier…?

No. First your script didn’t work second I don’t even know what you mean.

I mean putting the Tool inside ReplicatedStorage instead so that it’s easier to clone it that way

If you meant like copying the same script that’s still running when a Player joins the “Police”, then I don’t know why you’d wanna do that cause by the time it clones it’d already call FireClient()

I was talking about putting it in replicated storage in this :arrow_up:
And no I did not mean while the script was running.

1 Like

Could you add print statements then to debug the issue? It should work just fine provided the new script I gave

Did that, it works up to the point of playing the animation but doesn’t print anything?

My code with prints:

local RButton = game.StarterGui.ScreenGui.R
local IButton = game.StarterGui.ScreenGui.I
print("past the locals")
local char = game.Players:GetPlayerFromCharacter(script.Parent)
local part = char.Backpack.Handcuff.Handle
part.Touched:Connect(function(h)
    local hum = h.Parent:FindFirstChild("Humanoid")
    if not hum then return 
    elseif not hum:FindFirstChildOfClass("Animator") then local inst = Instance.new("Animator"); inst.Parent = hum end
    local animator = hum:WaitForChild("Animator")
    local animationTrack = animator:LoadAnimation(script.Animation)
    local R = game.ReplicatedStorage.R
    local I = game.ReplicatedStorage.I
    local O = game.ReplicatedStorage.O
    print("Animation is about to play...")
    animationTrack:Play()
    print("Animation is playing")
    RButton.Visible = true
    IButton.Visible = true
    print("GUI's should be showing...")
    I.OnServerEvent:Connect(function()
	    print("server fired for I")
	    hum.Torso.CFrame = CFrame.new(0.5, 4.65, 29.5)--where ever you wnat the arrested person to go
	    wait(1)--How long you want them to stay in prison for
	    hum.Torso.CFrame = CFrame.new(-0.75, 5.5, -0.75)--where ever you wnat the arrested person to go after they have been released from jail
    end)
    R.OnServerEvent:Connect(function()
	    print("server fired for R")
	    animationTrack:Stop()
    end)
end)

Why are you referencing the Buttons inside the StarterGui…? I am so confused

That would only work from the server side, so the Buttons wouldn’t detect any local input at all

I meant put print() statements in my script, the way you have your script handled is really unorganized & I recommend at least experimenting & debugging with mine a bit

No change. It still isn’t printing either.

1 Like

Ok, I almost got it to work. But this time it comes up with the error FireClient: player argument must be a Player object - Server - Script:15

This is my script:

local char = game.Players:GetPlayerFromCharacter(script.Parent)
local part = char.Backpack.Handcuff.Handle
part.Touched:Connect(function(h)
    local hum = h.Parent:FindFirstChild("Humanoid")
    if not hum then return 
    elseif not hum:FindFirstChildOfClass("Animator") then local inst = Instance.new("Animator"); inst.Parent = hum end
    local animator = hum:WaitForChild("Animator")
    local animationTrack = animator:LoadAnimation(script.Animation)
    local R = game.ReplicatedStorage.R
    local I = game.ReplicatedStorage.I
    local O = game.ReplicatedStorage.O
    print("Animation is about to play...")
    animationTrack:Play()
    print("Animation is playing")
    O:FireClient(h.Parent) --This is the important part
    print("GUI's should be showing...")
    I.OnServerEvent:Connect(function()
	    print("server fired for I")
	    hum.Torso.CFrame = CFrame.new(0.5, 4.65, 29.5)--where ever you wnat the arrested person to go
	    wait(1)--How long you want them to stay in prison for
	    hum.Torso.CFrame = CFrame.new(-0.75, 5.5, -0.75)--where ever you wnat the arrested person to go after they have been released from jail
    end)
    R.OnServerEvent:Connect(function()
	    print("server fired for R")
	    animationTrack:Stop()
    end)
end)

Hello. h.Parent is a character. You have to fire the userdata object of the player, meaning, replace O:FireClient(h.Parent) with

O:FireClient(game.Players:GetPlayerFromCharacter(h.Parent))

Also, I see absolutely no reason at all for implementing so many remote events. You should try to use just one remote function, do most of the activities on the server and try out what @Jackscarlett has suggested.

Server scripts do not replicate to the character, so this would cause an error.

Almost a solution. It worked, but now the GUI’s show for the wrong person. How do I make the GUI’s show for the person holding the tool? very annoying.

Have you already defined player who is holding the tool?

The tool’s Parent.Parent should be the player holding the tool. Try doing that.

Nope.

Ok. I’ll try that. Hopefully it works!

If the script is inside the tool, then you can easily define the player holding the tool by doing this:

local Tool = script.Parent
local PlrHoldingTool = game.Players:GetPlayersFromCharacter(Tool.Parent)

Then when you are firing the remote event, inside the parenthesis, add PlrHoldingTool.

O:FireServer(PlrHoldingTool)