local cashbutton = game.ServerStorage.Items.CashButton script.Parent.MouseButton1Click:Connect(function(plr) local playerpos = plr.Character.HumanoidRootPart.Position if debounce == false then cashbutton:clone(Vector3.new(playerpos+2,playerpos,playerpos)) end end)``` is my current script. not exactly sure how to fix this. I'm trying to make a clone of a button when clicked BUT it puts an error on the vector3 line.
You’re trying to add the number 2 to a vector 3. You need to do
cashbutton:clone(Vector3.new(playerpos.x +2, playerpos.y, playerpos.z))
to work. Although I suggest you do
local clone cashbutton:clone() clone.Position = Vector3.new(playerpos.x +2, playerpos.y, playerpos.z)
to make it more readable.
Please use the script format by typing ```lua, as it makes the script a lot more readable. Also formatting the script makes things nice and easy to read.
I think I did it. Hopefully it looks better
Thanks!! One question though, I’m getting another error on this line
local playerpos = plr.Character.HumanoidRootPart.Position
What is the error may I ask? Also are you doing this for a single client or for everyone?
Single client, and “Players.mrpulgo.PlayerGui.ScreenGui.TextButton.Script:5: attempt to index nil with ‘Character’”
local button = script.Parent local rs = game:GetService("ReplicatedStorage") local cashbutton = rs:WaitForChild("Items"):WaitForChild("CashButton") local debounce = false local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local hrp = character:WaitForChild("HumanoidRootPart") button.MouseButton1Click:Connect(function(plr) if debounce then return end debounce = true local position = hrp.Position local cbclone = cashbutton:Clone() cbclone.Parent = workspace cbclone.Position = (Vector3.new(position, position + 2, position)) task.wait(3) debounce = false end)
ServerStorage is only accessible from server scripts, also is this what you’re trying to achieve? I’ve moved the “cashbutton” to ReplicatedStorage as that directory can be accessed by both server scripts & local scripts.
This needs to be a local script as “game.Players.LocalPlayer” is only defined for local scripts.
Oh you’re using a script. You have to use local scripts to make it single client and to make it work. So change the script to
local plr = game.Players.LocalPlayer local cashbutton = game:WaitForChild(ReplicatedStorage).Items.CashButton local debounce = false script.Parent.MouseButton1Click:Connect(function() local playerpos = plr.Character.HumanoidRootPart.Position if debounce == false then debounce = true local clone = cashbutton:clone() clone.Parent = workspace clone.Position = Vector3.new(playerpos.x +2, playerpos.y, playerpos.z) task.wait(1) debounce = false end end)
Also move the CashButton the Replicated Storage. You can also use the above if you want.