script.Parent.ProximityPrompt.Triggered:Connect(function()
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
Character:MoveTo(game.Workspace.LeaveHouseTeleport.Position)
end)
I tried to fix everything from moving the script to server script and ending with a complete script change. Neither of these actions worked or generated further errors.
I also asked people on the dev forum, but they didnât tell me anything specific, just asked to send the entire script, or they wrote the script from scratch, completely out of context, e.g. adding debounce, changing ProximityPromt to a UI button or something like that.
Iâve already done a similar script in the GUI and it worked without a problem. Now, however, difficulties have arisen.
maybe this? I am still pondering my coding skills but this may help.
local Teleport = "part"
function Touch(hit)
if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true
local Pos = script.Parent.Parent:findFirstChild(Teleport)
hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end
script.Parent.Touched:connect(Touch)
The problem is that you have your LocalScript in workspace wich you shouldnât because LocalScripts are client side
to fix that replace it with a Script
The Script
local prompt = script.Parent.ProximityPrompt
prompt.Triggered:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
character:MoveTo(workspace.LeaveHouseTeleport.Position)
end)
I changed it to server script but the error â12:49:27.792 Workspace.Room.Door.Union.Script:4: attempt to index nil with âCharacterââ popped out
local Prompt = script.Parent.ProximityPrompt
Prompt.Triggered:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
character.HumanoidRootPart.CFrame = CFrame.new(workspace.LeaveHouseTeleport.Position)
end)
local Script = script
local Workspace = workspace
local Part = Script.Parent
local Prompt = Part.ProximityPrompt
local Teleport = Workspace.LeaveHouseTeleport
local function OnPromptTriggered(Player)
local Character = Player.Character
if not Character then return end
Character:PivotTo(Teleport.CFrame)
end
Prompt.Triggered:Connect(OnPromptTriggered)