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

Why Isn't my GUI button not spawning a part on a position?

Asked by 3 years ago

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:

1script.Parent.MouseButton1Down:Connect(function(plr)
2    local Part = Instance.new("Part")
3    Part.Size = Vector3.new(4.01, 5.464, 2.519)
4    Part.Parent = game.Workspace
5    Part.Position = plr.Character.HumanoidRootPart.Position
6end)
0
You need to define plr, and you need a remote event so that you can transfer the data to the server Frometa1998 35 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

MouseButton1Down does not return a plr. Therefore, you can use game.Players.LocalPlayer

1local plr = game.Players.LocalPlayer

Remove 'plr' line 1.

It should be:

1local plr = game.Players.LocalPlayer
2script.Parent.MouseButton1Down:Connect(function()
3    local Part = Instance.new("Part")
4    Part.Size = Vector3.new(4.01, 5.464, 2.519)
5    Part.Parent = game.Workspace
6    Part.Position = plr.Character.HumanoidRootPart.Position
7end)
Ad
Log in to vote
0
Answered by 3 years ago

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:

1REM = game.ReplicatedStorage:WaitForChild("RemoteEvent")
2script.Parent.MouseButton1Down:Connect(function(plr)
3    REM:FireServer(REM)
4end)

ServerScriptService Script:

1REM = game.ReplicatedStorage:WaitForChild("RemoteEvent")
2REM.OnServerEvent:Connect(function(plr)
3    local Part = Instance.new("Part")
4    Part.Size = Vector3.new(4.01, 5.464, 2.519)
5    Part.Parent = game.Workspace
6    local LP = game.Players.LocalPlayer
7    Part.Position = game.Players.LocalPlayer.Position
8 
9end)

Answer this question