Alright so, working on a spawning feature for a quick little game, been trying it out for a while but had a few issues and got it as far as I can by myself.
I’m pretty sure its just a basic issue from using GetPlayers()
Anyway, the intended result I’m trying to get is to have a box stored in serverstorage to spawn in-front of the player once the command “/spawn box” was used in chat.
Issue is, that the box does spawn, however in front of the most recently joined player, and not the speaker.
Been at this for awhile now and its becoming rather tiring to keep finding incorrect solutions.
Any help would be great to learn from and use, thank you!
Script:
function onChatted(msg, recipient, player)
local source = string.lower(player.Name) -- Converts name of speaker to lowercase
msg = string.lower(msg)
if (msg == "/spawn box") then --Chat Command
local box = game.ServerStorage.StorageBox
local boxclone = box:Clone()
for _,player in ipairs(game.Players:GetPlayers()) do
local character = player.Character
boxclone.Parent = workspace
boxclone.Position = character.Head.Position + Vector3.new(0,0,-5)
end
end
end
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end
game.Players.ChildAdded:connect(onPlayerEntered)