How to find the player that hit this part?

I am trying to find the player that hit a part, and set their movespeed to 0

this is my code

local function ChangeWalkSpeed(Player, NewWalkSpeed)
	if Player and Player.Character then
		if Player.Character:FindFirstChildWhichIsA("Humanoid") then
			Player.Character:FindFirstChildWhichIsA("Humanoid").WalkSpeed = NewWalkSpeed

ChangeWalkSpeed(game.Players, 0)

I know this wont work, because it has no logic to find the player who hit it, but i have no idea on how to write this script.
also think I should mention that this will be a singleplayer game, so if it is easier to just call everybody in the server that should work

1 Like

what the. after five seconds of this being posted someone liked the post…

im not writing the whole script, but it seems like you should look into this page

    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
    if plr then
        plr.Character.Humanoid.WalkSpeed = 0
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.