Hello, I am once again asking for your scripting support.
I am making a handcuff script with a cuff and jail function, everything else works but the teleportation part to the prison. I have been trying everything I know to try to fix it, but I can’t get it to work.
Here is my server script (This is only a part of it):
local prisons = workspace.Prison:GetChildren()
JailRemote.OnServerEvent:Connect(function(player, state, targetplayer) -- state == 'Jail' and targetplayer == workspace.Player1
if state == 'Jail' then
local GetPlayer = game.Players:FindFirstChild(targetplayer.Name)
targetplayer.HumanoidRootPart.Position = prisons[math.random(1,#prisons)].Position -- There are no errors and it just proceeds to the next line
GetPlayer.TeamColor = BrickColor.new("Smoky grey")
end
end)
I have tried with “SetPrimaryPartCFrame” but it just does the same thing. I researched for 3 days about this and tried everything, but most of it just did the same thing as it does now.
No errors at all? Maybe try adding some prints to see where it breaks?
local prisons = workspace.Prison:GetChildren()
JailRemote.OnServerEvent:Connect(function(player, state, targetplayer) -- state == 'Jail' and targetplayer == workspace.Player1
print("State: "..state)
if state == 'Jail' then
local GetPlayer = game.Players:FindFirstChild(targetplayer.Name)
local jailPosition = prisons[math.random(1,#prisons)].Position
print(jailPosition)
targetplayer.HumanoidRootPart.Position = jailPosition -- There are no errors and it just proceeds to the next line
GetPlayer.TeamColor = BrickColor.new("Smoky grey")
end
end)
I tried putting prints but the script “runs as it should”
script:
JailRemote.OnServerEvent:Connect(function(player, state, targetplayer)
print("State "..state)
if state == 'Jail' then
local GetPlayer = game.Players:FindFirstChild(targetplayer.Name)
local jailPosition = prisons[math.random(1,#prisons)].Position
print(jailPosition)
targetplayer.HumanoidRootPart.Position = jailPosition
print("Hello")
GetPlayer.TeamColor = BrickColor.new("Smoky grey")
end
end)
It worked for me when I changed the HumanoidRootPart.Position. I don’t know what’s different about your game. The only thing I can think of is that the jail’s position is a very long decimal point, maybe that is causing the problem? Maybe try setting the position to a rounder number.
JailRemote.OnServerEvent:Connect(function(player, state, targetplayer)
print("State "..state)
if state == 'Jail' then
local GetPlayer = game.Players:FindFirstChild(targetplayer.Name)
local jailPosition = prisons[math.random(1,#prisons)].Position
print(jailPosition)
targetplayer.HumanoidRootPart.Position = Vector3.new(100,10,10) --For testing purposes
print("Hello")
GetPlayer.TeamColor = BrickColor.new("Smoky grey")
end
end)
That works in the commandbar, but not in the script.
I didn’t think that this localscript would have anything to do with it, but here it is if it helps:
local Jailing = false
local Using = false
local PlayerCuffed -- On a client event the script changes this to the player being cuffed which is equal to workspace.Player1
Tool.Unequipped:Connect(function()
Player.PlayerGui.CuffGui.Enabled = false
if PlayerCuffed == nil then return end
Using = false
if not Jailing then
RemoteEvent:FireServer('UnCuff', PlayerCuffed)
PlayerCuffed = nil
end
end)
CuffGui.Jail.JailRound.JailButton.MouseButton1Down:Connect(function()
Jailing = true
local humanoid = Player.Character:FindFirstChildOfClass('Humanoid')
if humanoid then
humanoid:UnequipTools()
end
Using = false
RemoteEvent:FireServer('Jail', PlayerCuffed)
PlayerCuffed = nil
Jailing = false
end)
I researched a little more and found out that platformstand was making the player not teleport.
Added this and the script works:
local GetPlayer = game.Players:FindFirstChild(part.Name) -- part is equal to workspace.Player1
local prisons = workspace.Prison:GetChildren()
local jailPosition = prisons[math.random(1,#prisons)].CFrame
Using = false
targetbody.Anchored = false
workspace:FindFirstChild(part.Name).Humanoid.PlatformStand = false
GetPlayer.Character.Humanoid.PlatformStanding:Connect(function(isPlatformStanding)
if not isPlatformStanding then
part:SetPrimaryPartCFrame(jailPosition)
end
end)
Hopefully this can help someone that has the same problem as me. (if they will)