Hey there!
I’m trying to make a script that fires a remote event when a player uses a certain tool. But I want it only to fire for that player. I don’t know why it won’t work, and here’s my script:
local tool = script.Parent
local animation = tool.Animation
local Players = game:GetService("Players")
local player = Players.LocalPlayer
tool.Activated:Connect(function()
local Character = tool.Parent
local Humanoid = Character.Humanoid
local AnimationTrack = Humanoid:LoadAnimation(animation)
AnimationTrack:Play()
game.ReplicatedStorage.HealthEvent:FireClient(player)
wait(2.2)
tool:Destroy()
end)
remote:FireClient() can only be used on the server, if you want to send data to the server from your client you should do remote:FireServer()
Also, you don’t need to include the Player in the arguments because the player that fired the remote is automatically passed as the first argument on the server
local tool = script.Parent
local animation = tool.Animation
local Players = game:GetService("Players")
tool.Activated:Connect(function()
local Character = tool.Parent
local Humanoid = Character.Humanoid
local player = Players:GetPlayerFromCharacter(Character) -- get player from character method on the server
local AnimationTrack = Humanoid:LoadAnimation(animation)
AnimationTrack:Play()
game.ReplicatedStorage.HealthEvent:FireClient(player)
wait(2.2)
tool:Destroy()
end)