Hello, I really need help with my handcuffs and the scripts in it.
Almost everything works with my handcuffs, the only thing not working is the part where the serverscript teleports the player to their prison cell. I have looked everywhere for an answer, but no luck.
Here is a part of my serverscript:
RemoteEvent.OnServerEvent:Connect(function(player, state, part) -- state == 'Jail' and part == workspace.Player1 if state == 'Jail' then Using = false targetbody.Anchored = false workspace:FindFirstChild(part.Name).Humanoid.PlatformStand = false local GetPlayer = game.Players:FindFirstChild(part.Name) local jailPosition = prisons[math.random(1,#prisons)].Position -- This is the position GetPlayer.TeamColor = BrickColor.new("Smoky grey") GetPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(jailPosition) -- This is the problem, it works with the commandbar but not in the script end end)
There are no errors, but it won't move the player at all. I have tried using "SetPrimaryPartCFrame"
a part of my Localscript:
local PlayerCuffed -- Equal to workspace.Player1 local Jailing = false local Using = false 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 RemoteEvent:FireServer('Jail', PlayerCuffed) PlayerCuffed = nil Using = false Jailing = false end)
Hopefully I can find an answer to this question.
EDIT: I did find an answer look at my answer that I posted to this topic.
You defined the new CFrame wrong i think. Do this:
GetPlayer.Character.HumanoidRootPart.CFrame = jailPosition.CFrame
I'm not sure if this works tho, but i don't see another solution.
I think i know how to fix the position:
(Part of)
1.5. The Parent is Workspace
Then scroll down until you see the position
Name The Part HandcuffTeleportPart
Then Copy The Position
And Paste to G (Which is in The Script)
Dont Destroy, cause When You Playing it The Handcuff Teleport Part Will Transparent and non-collideable and anchored.
Then The Script (Copy-Paste Or Write, Insert it To Part of the Positions in Your Script)
local HTP = game.Workspace.HandcuffTeleportPart -- Booleans HTP.Anchored = true -- Bool HTP.CanCollide = false -- Bool HTP.Transparency = 1-- Float local HandCuff_Tele = Vector3.new(G) -- Replace G with The HandcuffTeleportPart Position -- Character GetPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(HandCuff_Tele)
Found out the problem was with platformstanding.
From roblox api: When true, the Humanoid is in a state where it is free-falling and cannot move.
Therefor I added this to my script:
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)