right now I have the name I just need to transfer the name from the localscript into the RemoteServer Connect script. I also dont check for humanoid, becuase I’m only looking for the knife .
then you can pass the name as a parameter when firing the remote event also it would be better to pass the humanoid
Makes sence, but one thing is I don’t know how to use parameters and I just started scripting this year. I will also add to check for humanoid to prevent further errors.
well when firing from the client with the remote event you can pass things through called parameters which can be anything such as a string, number etc like so:
killremote:FireServer(TargetHumanoid)
and then on the server it will receive the message and you can do whatever with it ig but it’ll look smthn like this:
killremote.OnServerEvent:Connect(function(Player, TargetHumanoid)
--kill Humanid
end)
bear in mind the player is automatically passed so you must always put player first on the server
Okay Thanks, but there is one problem. The Stack is ending at line 5 for some reason. I don’t know if you could figure out what is happening, because it’s not giving any errors.
**Local Script**
local tool = script.Parent
tool.Equipped:connect(function(mouse)
tool.Activated:connect(function()
if mouse.Target then
local SelectedPlayer = mouse.Target.Parent
if SelectedPlayer:FindFirstChild('Knife') and SelectedPlayer:FindFirstChild('Humanoid') then -- checks if clicked player has a knife
local Humanoid = SelectedPlayer:WaitForChild("Humanoid")
local repStor = game:GetService("ReplicatedStorage")
local killRemote = repStor:WaitForChild("KillRemote") --Requires a RemoteEvent named "KillRemote" to be childed under ReplicatedStorage
local TargetHumanoid = SelectedPlayer
killRemote:FireServer(TargetHumanoid) --Sends a message to activate the RemoteEvent
end
end
end)
end)
---------------------------------
**ServerScriptService Script**
local killRemote = script.Parent:WaitForChild("Kill")
killRemote.OnServerEvent:Connect(function(player, TargetHumanoid) -- I need to now get the selected player from the other script and
TargetHumanoid.Humanoid.Health = 0
end)
you’re sending the player’s character to the server not it’s humanoid so replace the TargetHumanoid variable on the client with SelectedPlayer:FindFirstChild(“Humanoid”)
Ok I just did that, but it seems like my server script isnt recieving the remote event.
local repStor = game:GetService("ReplicatedStorage")
local killRemote = repStor:WaitForChild("KillRemote")
print("worked1")
game.ReplicatedStorage.KillRemote.OnServerEvent:Connect(function(player, TargetHumanoid)
print("worked2")-- I need to now get the selected player from the other script and
end)
are there any warnings or errors in the output, I believe your script may get have gotten stuck waiting for the remote double check you got the name of the remote right in the waitforchild statement
I figured out how to make the server script find the event, but now Im having trouble killing the person with the knife. Iv’e never worked with parameters, so if you could figure out why it is stopping at line 5, we might be finished.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContentProvider = game:GetService("ContentProvider")
ReplicatedStorage:WaitForChild("KillHumanoidEvent").OnServerEvent:Connect(function(SelectedPlayer, TargetHumanoid)
local Humanoid = SelectedPlayer:WaitForChild("Humanoid")
Humanoid.Health = 0
print("Worked1")
end)
what error is it giving “Infinite yield possible”?
Yes its giving Infinite yield possible on ‘Players.Player1:WaitForChild(“Humanoid”)’, and the stack ends at line 5.
I fixed the infinite yeild possible, and now its telling me attemp nil with ‘Health’.
I finally figured out all of the mistakes I had made while coding. My first mistake was trying to kill through a local scrip, and my last mistake was not using waitforchild correctly. Thankk you too whomever helped!
Merry Christmas.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.