Hello! Im making a GUI that spawns a part and the position of the part goes Is basically the player Itself, however the problem Is the part doesn't teleport (Or goes) to the player Itself, this Is the script:
script.Parent.MouseButton1Down:Connect(function(plr) local Part = Instance.new("Part") Part.Size = Vector3.new(4.01, 5.464, 2.519) Part.Parent = game.Workspace Part.Position = plr.Character.HumanoidRootPart.Position end)
MouseButton1Down does not return a plr. Therefore, you can use game.Players.LocalPlayer
local plr = game.Players.LocalPlayer
Remove 'plr' line 1.
It should be:
local plr = game.Players.LocalPlayer script.Parent.MouseButton1Down:Connect(function() local Part = Instance.new("Part") Part.Size = Vector3.new(4.01, 5.464, 2.519) Part.Parent = game.Workspace Part.Position = plr.Character.HumanoidRootPart.Position end)
You need a remote to do this. Use A RemoteEvent in Replicated Storage, Fire it from your TextButton, and make the actual script in ServerScriptService. Make sure the script in ServerScriptService isnt a localscript.
TextButton Script:
REM = game.ReplicatedStorage:WaitForChild("RemoteEvent") script.Parent.MouseButton1Down:Connect(function(plr) REM:FireServer(REM) end)
ServerScriptService Script:
REM = game.ReplicatedStorage:WaitForChild("RemoteEvent") REM.OnServerEvent:Connect(function(plr) local Part = Instance.new("Part") Part.Size = Vector3.new(4.01, 5.464, 2.519) Part.Parent = game.Workspace local LP = game.Players.LocalPlayer Part.Position = game.Players.LocalPlayer.Position end)