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)
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)
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()
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
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)
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 @JackscarIitt 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.