Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to concatenate a string?

Asked by 10 years ago

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

Log in to vote
1
Answered by
Tesouro 407 Moderation Voter
10 years ago
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.

0
Thanks. Would I get the humanoid from local human = part.Parent:findFirstChild("Humanoid") ? MasterDaniel 320 — 10y
0
Yes. Perci1 4988 — 10y
0
yap, yw Tesouro 407 — 10y
Ad

Answer this question