function onClick(mouse) plr = game.Players.LocalPlayer script.Parent.MouseButton1Click:connect(function() pcall(function() local Pos = plr.Character:GetPrimaryPartCFrame() plr:LoadCharacter() plr.Character:SetPrimaryPartCFrame(Pos) if plr.Character:FindFirstChild("ForceField") then plr.Character["ForceField"]:Destroy() end end) end) end script.Parent.MouseButton1Down:connect(onClick)
Works perfectly in studio, but doesn't work in game.
[it is a local script]
I checked the log using F9, and nothing was there.
Well, first off that is not how you use pcall.
Whenever you call a pcall function you need 2 arguments, they can be named whatever (I think), but mostly people just do success, and error
so how to do to a pcall
function Good() print("hi") end local suc, err = pcall(Good) if suc then --do stuff end
Now, looking at your code, it looks like you have no reason for a pcall (correct me if I'm wrong)
P.S you don't need 'mouse' as an argument.
If you are doing this with a gui, having another click function is pointless
[EDIT]
So LoadCharacter only works on the server. How can we fix it? Remote events!
Create a remote event and place it in RemoteStorage Name it whatever, and put the server script wherever?
Inside the script, put this
local re = --path to remote re.OnServerEvent:connect(function(player) local Pos = plr.Character:GetPrimaryPartCFrame() player:LoadCharacter() player.Character:SetPrimaryPartCFrame(Pos) if player.Character:FindFirstChild("ForceField") then player.Character["ForceField"]:Destroy() end end)
Inside the local script put
plr = game.Players.LocalPlayer local re = --path to remote event script.Parent.MouseButton1Click:connect(function() re:FireServer() end)
Helpful? Make sure to accept this answer! Comments? Questions? Concerns? Make sure to ask!
Did I get anything wrong? Please don't hate, just tell me!
sources Pcall information