Script Will Not Load?

So this script I was making don’t work:

LocalScript

local tl = script.Parent.Parent.Parent:FindFirstChild("body").frame1.Money_Holder_back.TextLabel
script.Parent.Parent:FindFirstChild("Events").Loader.OnClientEvent:Connect(function(player, money)
	local s, e = pcall(function()
		tl.Text = tostring(money)
	end)
	
	if s then
		print("Money: Loaded")
	else
		tl.Text = "(Could Not Load Money)"
		error(e)
	end
end)

Server

local statsModule = require(script.Parent.Stats)
local remoteEvent = script.Parent:WaitForChild("Events"):FindFirstChild("Loader")

game.StarterPlayer.CharacterWalkSpeed = 0
game.StarterPlayer.CharacterJumpHeight = 0
-- // Stats

local startMoney = statsModule.StartMoney

print(startMoney)

local plr = game.Players.PlayerAdded:Wait()
remoteEvent:FireClient(plr, startMoney)

So it’s not firing (I’m guessing)

PlayerAdded doesn’t work that way, you have to do instead

game.Players.PlayerAdded:Connect(function(plr)
   remoteEvent:FireClient(plr, startMoney)
end)

Where plr is the player that is being added.

ALSO, you can’t call “LocalPlayer” from the server, instead do

game.Players.PlayerAdded:Connect(function(plr)
   remoteEvent:FireClient(plr, startMoney)
   plr.CharacterAdded:Connect(function(char)
         char.Humanoid.WalkSpeed = 0
         char.JumpPower.WalkSpeed = 0
   end)
end)
1 Like

Yes but it is gonna fire multiple times. I dont want it to fire more than once, one one time

local hasFired = false

-- event
   if hasFired then return end
   hasFired = true
-- end event

made a small mistake by not setting hasFired to true when the event fires

1 Like

Yep, just finally use

local hasFired = false


game.Players.PlayerAdded:Connect(function(plr)
   if hasFired then return end
   hasFired = true
   remoteEvent:FireClient(plr, startMoney)
   plr.CharacterAdded:Connect(function(char)
         char.Humanoid.WalkSpeed = 0
         char.JumpPower.WalkSpeed = 0
   end)
end)

I think I will just put everything inside 1 script, it works now

1 Like