Script clones models to server creator instead of player who triggered event

I’m making a game where when you press a GUI button, whatever you typed in the textbox next to it spawns next to you. Right now I’m encountering an issue that spawns things next to the player who joined the server first rather than the player who clicked the button themselves.

local repstorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humroot = character:WaitForChild("HumanoidRootPart")

local RE = game.ReplicatedStorage.RemoteEvent

...

RE.OnServerEvent:Connect(function(plr, textInput)
	if repstorage.Stuff:FindFirstChild(textInput) then
		local model = repstorage.Stuff:FindFirstChild(textInput)
		local modelclone = model:Clone()
		
		modelclone.Parent = workspace
		modelclone:PivotTo(humroot.CFrame)
		modelclone:TranslateBy(Vector3.new(5, -1, 5))
	else
		...
	end
end)

get the humroot of the plr variable, not player (in the event)

1 Like

Works perfectly now, thanks!

this is a placeholder because Roblox wants me to meet the minimum char limit

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.