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

How do you fetch the players name in a script (More context when clicked)?

Asked by 1 year ago

Im making it so that theres a model in server storage and it has a script inside of it and what im trying to do with that script is that it gets a players name then gets the character then places the model in the players position. Then using another script that when clicked it will clone model and put in in workspace. This is the script which is in the model

local brickBlast = script.Parent

for i,v in pairs(game.Players:GetPlayers()) do

wait()


local player = v.Name


brickBlast.PrimaryPart = brickBlast.Center
brickBlast:SetPrimaryPartCFrame(CFrame.new(player.Character.HumanoidRootPart.Position))

end

1 answer

Log in to vote
0
Answered by 1 year ago

A little unsure about what you're exactly looking for but you can get the player and the character like this

-- runs every time a new player joins
game.Players.PlayerAdded:Connect(function(player)
    -- runs whenever the character spawns
    player.CharacterAdded:Connect(function(character)
        -- would be where next part goes
    end
end)

from that you can use this to move the model to the character. change BrickBlast to whatever your model is called

game.ServerStorage.BrickBlast:SetPrimaryPartCFrame(character.PrimaryPart.CFrame)

Also know that no scripts will run while inside server storage. This would go inside serverscriptservice.

Ad

Answer this question