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

FireClient not working?

Alright, for some odd reason the local script is not receiving the FireClient(). I have a regular script in the ServerScriptService which loads the stats, while there is a local script in the ServerStorage that is cloned into the client. In the local script, it never prints when the Client is Fired. Here is the ServerScriptService script:

local DataStore = game:GetService("DataStoreService")
function Joined(player)
local stats = game.ServerStorage.Stats:clone()
stats.Parent = player
local key = "user_" .. player.userId
local a = DataStore:GetDataStore("Shillings")
local b = DataStore:GetDataStore("Bank")
Items = {}
Stackable = {}
Amount = {}
local Income = 0
local Rank = ""
a:UpdateAsync(key, function(oldValue)
	Shillings = oldValue or 0
end)
b:UpdateAsync(key, function(oldValue)
	Bank = oldValue or 0
end)
for i=1,10 do
	local c = DataStore:GetDataStore("Item"..i)
	c:UpdateAsync(key, function(oldValue)
		table.insert(Items,i,oldValue or "None")
	end)
	local d = DataStore:GetDataStore("Stackable"..i)
	d:UpdateAsync(key, function(oldValue)
	table.insert(Stackable,i,oldValue or false)
	end)
	local e = DataStore:GetDataStore("Amount"..i)
	e:UpdateAsync(key, function(oldValue)
	table.insert(Amount,i,oldValue or 0)
	end)
end
if player:GetRankInGroup(1114631) == 0 and player:GetRankInGroup(1079272) == 0 and player:GetRankInGroup(1080391) == 0 then
	Income = 10
	Rank = "Civilian"
elseif player:GetRankInGroup(1114631) >= player:GetRankInGroup(1079272) and player:GetRankInGroup(1114631) >= player:GetRankInGroup(1080391) then
		Rank = tostring(player:GetRoleInGroup(11141631))
		if player:GetRankInGroup(11141631)== 1 then
			Income = 10
		elseif player:GetRankInGroup(11141631) > 1 and player:GetRankInGroup(11141631)<= 9 then
			Income = 100
		elseif player:GetRankInGroup(11141631) > 9 and player:GetRankInGroup(11141631) <= 16 then
			Income = 250
		elseif player:GetRankInGroup(11141631) > 16 and player:GetRankInGroup(11141631) <= 200 then
			Income = 500
		elseif player:GetRankInGroup(11141631) > 200 then
			Income = 1000
		end
elseif player:GetRankInGroup(1114631) <= player:GetRankInGroup(1079272) and player:GetRankInGroup(1079272) >= player:GetRankInGroup(1080391) then
			Rank = tostring(player:GetRoleInGroup(1079272))
			if player:GetRankInGroup(1079272) == 237 then
				Income = 10
			elseif player:GetRankInGroup(1079272) > 237 and player:GetRankInGroup(1079272) <= 241 then
				Income = 100
			elseif player:GetRankInGroup(1079272) > 241 and player:GetRankInGroup(1079272) <= 248 then
				Income = 250
			elseif player:GetRankInGroup(1079272) > 248 and player:GetRankInGroup(1079272) <= 251 then
				Income = 500
			elseif player:GetRankInGroup(1079272) > 251 then
				Income = 1000
				
			end
			
elseif player:GetRankInGroup(1080391) >= player:GetRankInGroup(1114631) and player:GetRankInGroup(1080391) >= player:GetRankInGroup(1079272) then
		Rank = tostring(player:GetRoleInGroup(1080391))
		if player:GetRankInGroup(1080391) == 1 then
			Income = 10
		elseif player:GetRankInGroup(1080391) > 1 and player:GetRankInGroup(1080391) <= 4 then
			Income = 100
		elseif player:GetRankInGroup(1080391) > 4 and player:GetRankInGroup(1080391) <= 8 then
			Income = 250
		elseif player:GetRankInGroup(1080391) > 8 and player:GetRankInGroup(1080391) <= 9 then
			Income = 500
		elseif player:GetRankInGroup(1080391) > 9 then
			Income = 1000
		end
		end
repeat wait()
until #Amount == 10

player:WaitForChild("Stats").Main:FireClient(player,1,Shillings,Bank,Income,Rank,Items,Stackable,Amount)
print(player,1,Shillings,Bank,Income,Rank,Items,Stackable,Amount)
end
game.Players.PlayerAdded:connect(Joined)

Here is the local script, which is cloned:

local Stats = {
	["Shillings"] = 0,
	["Bank"] = 0,
	["Income"] = 0,
	["Rank"] = "",
	["Slot_1"] = {
		["Name"] = "None",
		["Stackable"] = false,
		["Amount"] = 0
	},
	["Slot_2"] = {
		["Name"] = "None",
		["Stackable"] = false,
		["Amount"] = 0
	},
	["Slot_3"] = {
		["Name"] = "None",
		["Stackable"] = false,
		["Amount"] = 0
	},
	["Slot_4"] = {
		["Name"] = "None",
		["Stackable"] = false,
		["Amount"] = 0
	},
	["Slot_5"] = {
		["Name"] = "None",
		["Stackable"] = false,
		["Amount"] = 0
	},
	["Slot_6"] = {
		["Name"] = "None",
		["Stackable"] = false,
		["Amount"] = 0
	},
	["Slot_7"] = {
		["Name"] = "None",
		["Stackable"] = false,
		["Amount"] = 0
	},
	["Slot_8"] = {
		["Name"] = "None",
		["Stackable"] = false,
		["Amount"] = 0
	},
	["Slot_9"] = {
		["Name"] = "None",
		["Stackable"] = false,
		["Amount"] = 0
	},
	["Slot_10"] = {
		["Name"] = "None",
		["Stackable"] = false,
		["Amount"] = 0
	}
}
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
script.Main.OnClientEvent:connect(function(Type,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
	if Type == 1 then
		
		print(arg1) -- doesn't print
		Stats["Shillings"] = arg1
		print(arg2)
		Stats["Bank"] = arg2
		print(arg3)
		Stats["Income"] = arg3
		print(arg4)
		Stats["Rank"] = arg4

		for i=1,10 do
			print(arg5[i])
			print(arg6[i])
			print(arg7[i])
			Stats["Slot_"..i]["Name"] = arg5[i]
			Stats["Slot_"..i]["Stackable"] = arg6[i]
			Stats["Slot_"..i]["Amount"] = arg7[i]
			end
		for i,v in pairs(#Stats) do
			print(v)
		end	
	
	
	local Gui = game.Players.LocalPlayer.PlayerScripts.StatsGui
	Gui.Frame["Name"].Text = script.Parent.Name
	Gui.Frame.Income.Text = "Income: "..tostring(Stats["Income"])
	Gui.Frame.Rank.Text = Stats["Rank"]
	Gui.Frame.Shillings.Text = tostring(Stats["Shillings"]).."Shillings"
	Gui.Frame.Bank.Text = tostring(Stats["Bank"])
	elseif Type == 2 then
		if Stats["Shillings"] >= arg1 then 
		Stats["Shillings"] = Stats["Shillings"] - arg1
		Obtain(script.Parent,arg2,arg3,arg4)
		end
		
end

end)

function Obtain(player,Item,Stack,Amount)
	for i=1,10 do
	print(Stats["Slot_"..i]["Name"])
		if Stats["Slot_"..i]["Name"] == "" then
			Stats["Slot_"..i]["Name"] = Item
			Stats["Slot_"..i]["Stackable"] = Stack
			Stats["Slot_"..i]["Amount"] = Amount
			break
		end
		end
end


function CharacterAdd(Character)
	local plr = game.Players:GetPlayerFromCharacter(Character)
	plr.Backpack.StatsGui.Parent = plr.PlayerGui
end
game.Players.LocalPlayer.CharacterAdded:connect(CharacterAdd)



2 answers

✓ Accepted answer

Since the LocalScript is in ServerStorage, it's not printing anything because on the client-side, ServerStorage and ServerScriptService don't exist. You'll have to put the LocalScript in another location. I suggest putting it inside ReplicatedFirst to replicate it across all the clients

6 comments

1

Basically, all things in it are replicated to all clients first before anything else. This is very useful for creating loading guis, tutorials, etc.

1

There's a tutorial that uses ReplicatedFirst in the ROBLOX Wiki: http://wiki.roblox.com/index.php?title=Custom_loading_screen

0

Is it fine if I put it in the Lighting?

1

Lighting just puts it there. If you want the script to go to all clients automatically, then no. I would not recommend Lighting.

0

How would I make it so that the stats would be transferred to the script?

0

I'm not so sure about that...

I would reccomend doing creating the server event in your script instead of adding physically

-- Inside Server Script
local event = Instance.new("RemoteEvent") -- creates the event object
event.Parent = game.Workspace -- puts the event into the Workspace, or wherever you want it
event.Name = "MyServerEvent" -- giving a name to the event so we can fire it specifically elsewhere
event.OnServerEvent:connect(function() -- define the function that will be called when the event is fired
        -- this is where you put all the code you want to run when the event is fired
	game.Workspace.Baseplate.BrickColor = BrickColor.Random() -- Something random//Put your code here
end)

I would also put that at the start of your server script so that it dosen't create more that one

Then When you want to call that Event just do this when ever you want to fire the event

ame.Workspace.MyServerEvent:FireServer() -- Or wherever that event is located in your game

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