Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to concatenate a string?

So in this function I have (which I have previously asked a question about) I find the player who hit a brick and then find their bus in the workspace. However I recieve an error trying to concatenate this string.

Detector = script.Parent

function onTouch(part)
	local player = game.Players:GetPlayerFromCharacter(part)
	local bus = Workspace:FindFirstChild(player.."'s Car")
-- do stuff
end
Detector.Touched:connect(onTouch)

The model in the workspace is called "Player 1's Car" (in test mode) but the function breaks when I do this. Can anyone see why?

1 answer

✓ Accepted answer
local player = game.Players:GetPlayerFromCharacter(part)

That is trying to get the player from a limb. Just change:

local player = game.Players:GetPlayerFromCharacter(part.Parent)

But don't forget to check if it really is a character, search for a Humanoid.

3 comments

0

Thanks. Would I get the humanoid from local human = part.Parent:findFirstChild("Humanoid") ?

0

Yes.

0

yap, yw

This discussion is preserved as it was. New answers, comments, and votes are closed.