Hi there! The character isn’t moving in this script.
function onClick()
local player = game.Players.LocalPlayer
local character = player.Character
local math = math.random(1, 2)
if math == 1 then
print('ello')
character.Position = game.Workspace.Arena.PlayerSpawns.Part1.Position
end
if math == 2 then
character.Position = game.Workspace.Arena.PlayerSpawns.Part2.Position
print('asdfasdfasdf')
end
end
script.Parent.MouseButton1Click:Connect(onClick)
I belive that this is due to the fact that I can’t move the character with ‘Position?’
Characters are models. Models don’t have Position property. I suggest teleporting characters by changing character’s HumanoidRootPart's CFrame to a teleportation position. An example:
-- Teleport to position -64, 32, 0;
game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(-64, 32, 0)
Just like what @Spiderr12PL said, the character you are referencing to is a model and if you look on the properties of the model there is no position property so that you need to change the CFrame of the HumanoidRootPart which is basically the primarypart of a character.
Furthermore, assuming that you called the player using game.Players.LocalPlayer it seems that you are doing this client sided, so meaning that other players can’t see that you teleported somewhere only yourself, if you want other players to see you teleporting then send a remote event to the server and then you can do the teleport handling there.
The Character’s Children sometimes will not 100% load all the time, which is why you should call WaitForChild() so that the script can yield its code and wait until that said “HumanoidRootPart” is found
I also think you forgot to create your local function
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local function OnClick()
local RNG = math.random(1, 2)
if RNG == 1 then
print("ello")
HRP.Position = workspace.Arena.PlayerSpawns.Part1.Position
else
HRP.Position = workspace.Arena.PlayerSpawns.Part2.Position
end
end
script.Parent.MouseButton1Click:Connect(OnClick)