Hello roblox, whenever I connect onto the remoteevent once it was fired, nothing happens. I try to look in the output, but I see nothing.
Here’s the code:
local remote = game.ReplicatedStorage.Jumpscare
local jumpscare = game.Workspace.monsterloltest.jumpscare
local monster = game.Workspace.monsterloltest.Humanoid
local animload = monster:LoadAnimation(jumpscare)
remote.OnServerEvent:Connect(function()
print("hi")
animload:Play()
end)
local hitbox = script.Parent
local cooldown = false
local remote = game.ReplicatedStorage.Jumpscare
hitbox.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if not cooldown then
local human = plr.Character.Humanoid
if human.Health > 0 then
cooldown = true
remote:FireClient(plr)
wait(2)
human.Health = 0
cooldown = false
end
end
end
end)
I recommend re-reading the RemoteEvent documentation on the Roblox Creator Documentation to develop a clearer understanding of it.
Anyways, for your problem:
Your Script is missing the player argument from OnServerEvent, and I assume you’ll need it since your jumpscare code should activate if the player that touched it is still alive in the server.
Inside a Script:
remote.OnServerEvent:Connect(function(player)
--[[
the player argument (variable inside the function's brackets) is the player to get jumpscared
]]
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 then
humanoid.Health = 0
animload:Play()
end
end)
In your LocalScript, you’re using the wrong method to call the RemoteEvent for the server. :FireClient() is used only for server-to-client communication, but in this case you’ll need to use client-to-server communication, and in that case you’ll use :FireServer() instead:
Inside your LocalScript:
hitbox.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not cooldown then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 then
cooldown = true
-- No need to add the player instance into the arguments, as it is done by default
remote:FireServer()
-- I recommend using task.wait() instead of wait(), they both serve the same purpose but task.wait() is "newer"
task.wait(2)
cooldown = false
end
end
end)
Based on the code you provided, it looks like you’re trying to play a jumpscare animation on the monster when a RemoteEvent is fired on the server. Here are a few things to check to help debug the issue:
Make sure that the RemoteEvent is actually firing on the server. You can add a print statement inside the RemoteEvent function to check if it’s being called:
Check that the animation is actually loading correctly. You can add a print statement to check if the animation was successfully loaded:
local animload = monster:LoadAnimation(jumpscare)
print(animload) -- Should print the Animation object if successfully loaded
Make sure that the monster’s humanoid is not in a state that prevents animations from playing, such as being dead or in a ragdoll state.
Double-check that the jumpscare animation is set up correctly in the Workspace. Make sure that the animation is named correctly, and that the monster’s animation controller is properly configured to play the animation.
If none of these steps help solve the issue, you may need to provide more information or context to help diagnose the problem.
You wanted to make the model start animated while player touched the part right? I think it didn’t work since it was a localscript in your touch part. That’s works through player’s client while part is like a server instance
this is my version idk what
local hitbox = script.Parent
local cooldown = false
hitbox.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr and not cooldown then
local human = plr.Character:WaitForChild("Humanoid")
if human.Health > 0 then
cooldown = true
local jumpscare = script:WaitForChild("jumpscare")
local monster = script.Parent.Parent:WaitForChild("Humanoid")
print("hi")
local animload = monster:LoadAnimation(jumpscare)
animload:Play()
wait(2)
human.Health = 0
cooldown = false
end
end
end)