A little explanation:
I am currently working in a turn based game, i have gotten nothing done to be fair, i’m new to scripting and im having trouble finding a player’s model.
I’ve been stuck on this for three days, i seriously need help, i’ve tried to make a variable of the player name and acces the model trough that but it doesn’t work
im kind of desperate and i couldn’t find a tutorial that would help.
The problem is I need to lock the player in place once they enter in contact with the enemy (starting the fight) i’m currently just testing the locking the player down.
Problem is i can’t seem to acces the humanoid part to set the walkspeed to 0
please if you know anything that could help, tell me
If you have a reference to the actual player instance you can use its Character property. That gives you a reference to their character model in Workspace.
Alternatively you can get the character from the Player.CharacterAdded event.
If you already have the player name, then this is easy. What you could do is: local Players = game:GetService("Players") local PlayerName = "playernamehere" local PlayerChar = Players[PlayerName].Character or Players[PlayerName].CharacterAdded:Wait()
Basically what that does is it grabs the Players Character, but if its nil then we wait for it to be added by using the :Wait() method for RBXScriptSignal. This also saves it into a variable, so you could easily do PlayerChar.Humanoid.WalkSpeed = 0
No problem, also for other threads you will make in Scripting Support, please add your current code that is having the issue. It will help you and people trying to debug your code.
Alright, so you really dont need to do what anyone told you now. It’s a bit funny, but you had the right idea. So onto the code part, you can actually get the character from your OnTouch function.
local function OnTouch(hit)
print(“Teleport”)
local torso = hit.Parent:findFirstChild(“Torso”)
local theirchar = nil
if (torso ~= nil) then
theirchar = torso.Parent
torso.CFrame= CFrame.new(Vector3.new(-23.8, 0.6, -39.2))
theirchar.Humanoid.WalkSpeed = 0
print (theirchar.Name .. " has started a fight with a bandit")
end
end
script.Parent.Touched:Connect(OnTouch)
Remove the onCharacterAdded code now, you dont need it, also make sure to remove
the player added line too.
Thanks a lot, I didn’t post it initially because i tought people would laugh at what i had done, its obvious i have no idea what im doing, thanks for the help
Nope, no one does that here. Like at all. We all are grown up enough not to make fun of eachother, sure we might have a little giggle but thats respectful. Make sure to mark my post as a solution if it works.