Hello, I’m making a fighting game where you must enter a portal to enable “canFight”, and if canFight is off, you can’t punch other players. However, look at this.
the script
local portal = script.Parent
local plainsSpawnPoint = game.Workspace:WaitForChild("Islands"):WaitForChild("PlainsIsland"):WaitForChild("plainsSpawnPoint")
local snowySpawnPoint = game.Workspace:WaitForChild("Islands"):WaitForChild("SnowyIsland"):WaitForChild("snowySpawnPoint") -- Sets the variable to the corresponding SpawnPoint
local desertSpawnPoint = game.Workspace:WaitForChild("Islands"):WaitForChild("DesertIsland"):WaitForChild("desertSpawnPoint")
local Players = game:GetService("Players")
portal.Touched:Connect(function(touchedPlayer)
if touchedPlayer and touchedPlayer.Parent:WaitForChild("Humanoid") then -- Determines if the touched object is a player
local player = Players:GetPlayerFromCharacter(touchedPlayer.Parent)
print(player)
local canFight = player:FindFirstChild("canFight")
if not canFight then
print("nil")
end
if canFight then
canFight.Value = true
local character = touchedPlayer.Parent -- Makes your life easier
-- Lines of code below set the SpawnPoints' positions to their CFrames
local plainsSpawnPointPosition = CFrame.new(plainsSpawnPoint.CFrame.X, plainsSpawnPoint.CFrame.Y + 5, plainsSpawnPoint.CFrame.Z)
local snowySpawnPointPosition = CFrame.new(snowySpawnPoint.CFrame.X, snowySpawnPoint.CFrame.Y + 5, snowySpawnPoint.CFrame.Z)
local desertSpawnPointPosition = CFrame.new(desertSpawnPoint.CFrame.X, desertSpawnPoint.CFrame.Y + 5, desertSpawnPoint.CFrame.Z)
local RNG = math.random(1,3) -- Determines an RNG number with math.random
if RNG == 1 then -- Determines if RNG = 1
character:SetPrimaryPartCFrame(plainsSpawnPointPosition) -- Sets the player's position to the spawn pad
elseif RNG == 2 then -- If RNG wasn't 1, detects if RNG = 2
character:SetPrimaryPartCFrame(snowySpawnPointPosition)
elseif RNG == 3 then -- If RNG wasn't 2, detects if RNG = 3
character:SetPrimaryPartCFrame(desertSpawnPointPosition)
end
task.wait(1)
end
end
end)
The explorer when I hit play:
The output:
WHAT DID I DO WRONG??? PLZ TELL ME!!!