Character loading in wrong position

Hello, I am making a game a longer time, and i made myself a script that will load character on specific position when the player joins, it worked every time i was testing the game, but suddenly today when i tested the game, it spawned me at completely different position, i tried to change the spawning position in the script, but it still spawns me in the same wrong place, there is nothing else that can potentially spawn me elsewhere because when i disable the loading script, then it will not even load my character, so this is the only script that handles character loading. I don’t know if there is something wrong with my script, because it was all the same for a decent amount of time now and suddenly it stopped working propelry. The script is placed in ServerScriptService and it is a server script.

The script:
`local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local RespawnEvent = ReplicatedStorage:WaitForChild(“RespawnEvent”)
local FreshRestart = ReplicatedStorage:WaitForChild(“FreshRestartartart”)
local GuiReset = ReplicatedStorage:WaitForChild(“GuiReset”)
local OnDiedTextEdit = ReplicatedStorage:WaitForChild(“OnDiedTextEdit”)
local OnDiedFlashlightButton = ReplicatedStorage:WaitForChild(“OnDiedFlashlightButton”)

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
– Check if the character has a humanoid and set its position and rotation
local humanoid = character:WaitForChild(“Humanoid”)
local rootPart = humanoid.Parent:WaitForChild(“HumanoidRootPart”)

	-- Set position and rotate 90 degrees to the right (around the y-axis)
	local orientation = CFrame.Angles(0, math.rad(270), 0)
	rootPart.CFrame = CFrame.new(Vector3.new(78.804, 247.459, 1.987)) * orientation -- Default spawn position

	-- Connect to the Died event to remove parts when the player dies
	humanoid.Died:Connect(function()
		GuiReset:FireClient(player)
		-- Remove all parts of the character after a delay
		wait(3)
		for _, part in pairs(character:GetDescendants()) do
			if part:IsA("BasePart") then
				part:Destroy()
			end
		end
	end)

	
	
end)

player:LoadCharacter()

end)

local Players = game:GetService(“Players”)
local MarketplaceService = game:GetService(“MarketplaceService”)

local reviveID = 1734251322

MarketplaceService.ProcessReceipt = function(receiptInfo)
local plr = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not plr then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo.ProductId == reviveID then
plr:LoadCharacter()

	-- Wait for the character to be added
	local character = plr.Character or plr.CharacterAdded:Wait()
	wait()  -- Additional delay for stability, adjust as needed

	print("Character was loaded and server is still running haha")
	FreshRestart:FireClient(plr)
	print("Event was fired on client")
	OnDiedTextEdit:FireClient(plr)
	wait()
	OnDiedFlashlightButton:FireClient(plr)
	print("OnDiedFlashlight was fired!")
end
return Enum.ProductPurchaseDecision.PurchaseGranted

end`

I will be glad if someone found a way to make this work.

1 Like

It looks like it deformated the text so i try to show it here:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RespawnEvent = ReplicatedStorage:WaitForChild("RespawnEvent")
local FreshRestart = ReplicatedStorage:WaitForChild("FreshRestartartart")
local GuiReset = ReplicatedStorage:WaitForChild("GuiReset")
local OnDiedTextEdit = ReplicatedStorage:WaitForChild("OnDiedTextEdit")
local OnDiedFlashlightButton = ReplicatedStorage:WaitForChild("OnDiedFlashlightButton")


Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		-- Check if the character has a humanoid and set its position and rotation
		local humanoid = character:WaitForChild("Humanoid")
		local rootPart = humanoid.Parent:WaitForChild("HumanoidRootPart")

		-- Set position and rotate 90 degrees to the right (around the y-axis)
		local orientation = CFrame.Angles(0, math.rad(270), 0)
		rootPart.CFrame = CFrame.new(Vector3.new(78.804, 247.459, 1.987)) * orientation -- Default spawn position

		-- Connect to the Died event to remove parts when the player dies
		humanoid.Died:Connect(function()
			GuiReset:FireClient(player)
			-- Remove all parts of the character after a delay
			wait(3)
			for _, part in pairs(character:GetDescendants()) do
				if part:IsA("BasePart") then
					part:Destroy()
				end
			end
		end)

		
		
	end)

	player:LoadCharacter()
	
	
	

end)




local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local reviveID = 1734251322

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local plr = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not plr then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if receiptInfo.ProductId == reviveID then
		plr:LoadCharacter()

		-- Wait for the character to be added
		local character = plr.Character or plr.CharacterAdded:Wait()
		wait()  -- Additional delay for stability, adjust as needed

		print("Character was loaded and server is still running haha")
		FreshRestart:FireClient(plr)
		print("Event was fired on client")
		OnDiedTextEdit:FireClient(plr)
		wait()
		OnDiedFlashlightButton:FireClient(plr)
		print("OnDiedFlashlight was fired!")
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end
1 Like

Actually nevermind, I fixed it myself.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.