Basically I am trying to send the player name and class name to a local script. It only sends those values to the local script if a certain criteria is met. Whenever the criteria is met the code activates fine, but in the local script it says that the player name and class name are nil values. How can I make it so those aren't nil values?

Server

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ChangeClass = ReplicatedStorage:WaitForChild("ChangeClass")
local ClassChanging = ReplicatedStorage:WaitForChild("ClassChanging")

local Players = game:GetService("Players")

local Requirements = {["Ninja"] = 1,["Tank"] = 2}

local ServerStorage = game:GetService("ServerStorage")
local ServerClasses = ServerStorage:WaitForChild("Classes"):GetChildren()

local function ChangerPlayerClass(player,Text,Frame)
		print(player.Name.." sent "..Text.." to the server from "..Frame.Name)
	
	for name,requirements in pairs(Requirements) do
		if Text == name and player.LeaderStats.Level.Value >= requirements
		then if Frame.name == "MainFrame"
			then player.ClassLoadout.class.Value = name
				
				ClassChanging:FireClient(player,Text)-- sends the class to the client
				print(player.Name.." sent "..Text.." to Attributes")
				
				return player.ClassLoadout.class
			end--ends "if frame name"
		end	-- ends if statement
	end-- ends for statement
end--ends changeplayerclass function
ChangeClass.OnServerInvoke = ChangerPlayerClass

Local

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClassChanging = ReplicatedStorage:WaitForChild("ClassChanging")

ClassChanging.OnClientEvent:Connect(function(player, class)
	print("Recieved")
	local hum = player:WaitForChild("Humanoid")
	
	if class == "Ninja" then
		hum.WalkSpeed = 50
		else if class == "Tank" then
			hum.WalkSpeed = 25
		end
	end
end)--ends ClassChanging Event

1 comment

0

Not sure exactly what you're asking here, but try making sure they aren't nil on the server, before passing them to the client.