Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

LocalScript is not firing the ServerScript Please help! Why won't it work?

I have a localscript trying to fire a serverscript. The LS is placed in StarterGUI, the SS is placed in ServerStorage, the RemoteEvent in ReplicatedStorage.

Localscript

--Waits for player then fires ServerScript--
	
	game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local hrp = character:WaitForChild("HumanoidRootPart",3)
		
       if hrp then
			game.ReplicatedStorage.RemoteEvents.LBLoad:FireServer()
		else 
			
		end
    end)
end)

Serverscript

--Loads Leaderboard after finding local player in a localscript--
 game.ReplicatedStorage.RemoteEvents.LBLoad.OnServerEvent:Connect(function()
	

	game.Players.PlayerAdded:connect(function(p)
		local stats = Instance.new("IntValue")
		stats.Name = "leaderstats"
		stats.Parent = p
		
		local money = Instance.new("IntValue")
		money.Name = "Money"
		money.Value = 0
		money.Parent = stats
		local bounty = Instance.new("IntValue")
		bounty.Name = "Bounty"
		bounty.Value = 0
		bounty.Parent = stats
	end)

end)

I've also tried V

--Loads Leaderboard after finding local player in a localscript--
 game.ReplicatedStorage.RemoteEvents.LBLoad.OnServerEvent:Connect(function()
	

	
		local stats = Instance.new("IntValue")
		stats.Name = "leaderstats"
		stats.Parent = game.Players.PlayerAdded
		
		local money = Instance.new("IntValue")
		money.Name = "Money"
		money.Value = 0
		money.Parent = stats

		local bounty = Instance.new("IntValue")
		bounty.Name = "Bounty"
		bounty.Value = 0
		bounty.Parent = stats
	

end)

It isn't creating the leaderboard which means it is not firing the remotevent because "leaderstats in not a valid member of Player"

4 comments

0

Creating a leaderboard of this kind is done on the server, place this code in a server script

0

It is in a server script

0

First bit is ls second is ss

0

I was just thinking this. I will try that but it should still work I am just trying to learn about remotevents and i don't understand why it isn't working when im able i will combine them on a serverscript but this code is still trying to create it on the server so i dont understand.

1 answer

✓ Accepted answer

You don't do playeradded events or any characteradded events those should be only done in the server

Also I don't see a point on why you are using a local script for a leaderboard everything here can and should be done on a server

it should be more like

game.Players.PlayerAdded:Connect(function(player)

	local stats = Instance.new("IntValue")
	        stats.Name = "leaderstats"
	        stats.Parent = game.Players.PlayerAdded
	
	        local money = Instance.new("IntValue")
	        money.Name = "Money"
	        money.Value = 0
	        money.Parent = stats
	
	        local bounty = Instance.new("IntValue")
	        bounty.Name = "Bounty"
	        bounty.Value = 0
	        bounty.Parent = stats

end)

3 comments

0

The problem with this is it doesnt load the leaderboard every single time a player joins and once again the leaderboard is in a server script.

0

Thanks on the first part though.

0

Accepted because the first part, and I figured it out.

This discussion is preserved as it was. New answers, comments, and votes are closed.