I have been wanting to make a force choke, and it works server-side, which is excellent. There's a problem, though. When going ahead and clicking the torso of something with a humanoid in it, when the 'playchoke' event is fired, the server picks it up as my character being choked in the end. I'm confused, I believe I've done this correctly. A little support would be helpful, thanks. Here's some code from client-side and server-side:
Also, at the start of my Client-Side script, I have put the Player's Mouse's TargetFilter to nil, so it shouldn't choke my character if I'm clicking on models with humanoids:
v Client Script v
*-- Client-Side* local mouse = player:GetMouse() mouse.TargetFilter = nil mouse.Button1Down:Connect(function() if equipped == true then print('ok') if mouse.Target.Parent:FindFirstChild('Humanoid') then local mouseTarget = game.Players:GetPlayerFromCharacter(mouse.Target.Parent) print(mouseTarget) script.playchoke:FireServer(mouseTarget) -- the choke event print('doing choke') end end end)
v Server Script v
*-- Server-Side* script.Parent.client.playchoke.OnServerEvent:Connect(function(mouseTarget) print(mouseTarget) local dead = false local damage = 15 local char = mouseTarget.Character local humanoid = char.Humanoid while true do local anim = script.Parent.Handle.victumanim local animtrack = humanoid:LoadAnimation(anim) animtrack:Play() wait(0.1) humanoid.WalkSpeed = 0 humanoid.JumpPower = 0 humanoid:TakeDamage(damage) wait(0.1) print('should be choking') end end)
In the output, on the Server-Side script, the 'print(mousetarget)' comes up with my local player's name (me) and not the victum's name I clicked. On client-side, it goes ahead and prints the player's name that I've clicked on. I'm still very confused..
To transfer a player, and all properties, including name to the server, the simplest way would be to use a Remote Event
A remote event, specifically the OnServerEvent event of the remote event has an impicit player parameter (which you mistakenly used as the mouse target parameter), then all the arguments you provided when firing the remote event:
local remote = --remote location here remote:FireServer(...)
local remote = --remote location here remote.OnServerEvent:Connect(function(plr,...) end)
So, after correcting your OnServerEvent, the result would be :
script.Parent.client.playchoke.OnServerEvent:Connect(function(plr,mouseTarget) print(mouseTarget) local dead = false local char = mouseTarget.Character local humanoid = char.Humanoid for i = 1,7 do local anim = script.Parent.Handle.victumanim local animtrack = humanoid:LoadAnimation(anim) animtrack:Play() wait(0.1) humanoid.WalkSpeed = 0 humanoid.JumpPower = 0 humanoid:TakeDamage(15) wait(0.1) print('should be choking') end end)
FYI, you shouldn't just check whether if the mouse target has a humanoid, that could end up firing the event when you hover over an NPC, you should really check whether you can get a player from the character instead.
Hopefully This helped!