-
What do you want to achieve? I’m attempting to use string values to change a players class and give them hats and tools depending on the class.
-
What is the issue? The code I have written to check what class a user is in isn’t working, even though the string value is at the proper class name.
-
What solutions have you tried so far? Friends, scripting helpers.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--LocalScript event code:
ui.ClassSelect1.Officer.MouseButton1Click:Connect(function()
classvalue.Value = "Officer"
print("Firing oficer event!")
game.ReplicatedStorage.ClassJoined:FireServer(player)
end)
--Server Code
game.ReplicatedStorage.ClassJoined.OnServerEvent:Connect(function(player)
print("Event registered")
if player.TeamValue.Value == "UK" then
if player.ClassValue.Value == "Officer" then
print("User is officer!")
local officerhat = game.ReplicatedStorage.Items["British Officer Cap"]:Clone()
officerhat.Parent = game.Workspace[player.Name]:WaitForChild("Character")
local gun = game.ReplicatedStorage.Items["Webley Revolver\
"]:Clone()
gun.Parent = player.Backpack
player:LoadCharacter()
player.PlayerGui.ClassSystem.Enabled = false
elseif player.ClassValue.Value == "MachineGunner" then
elseif player.ClassValue.Value == "Rifleman" then
end
elseif player.TeamValue.Value == "DE" then
if player.ClassValue.Value == "Officer" then
elseif player.ClassValue.Value == "MachineGunner" then
elseif player.ClassValue.Value == "Rifleman" then
end
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
When using :FireServer()
you don’t need to pass the player as Roblox automatically does it for you. Also I think you might need to give us more information like what is ClassValue? and how are you setting the TeamValue? Currently the only thing I can think of at the moment when seeing this is that the players current team value is spelt incorrectly or doesn’t equal anything.
Edit: Ok I think I know what the issue is. It seems like you’re setting the ClassValue on the client which I’m pretty sure won’t change on the server. I’m assuming ClassValue is a stringvalue inside the players character? So you should probably do :FireServer("Officer")
and then on the server set the players ClassValue to that by doing something like this
game.ReplicatedStorage.ClassJoined.OnServerEvent:Connect(function(Player,Class)
if type(Class) == "string" then
Player.Character.ClassValue.Value = Class
--do your ifs
end
That makes a lot of sense, I’ll try it right now! Thanks!
I’m attempting this, however I don’t believe the string message is being passed through. Heres my fire client and on server event code:
--Server
game.ReplicatedStorage.ClassJoined.OnServerEvent:Connect(function(player, message)
--local
game.ReplicatedStorage.ClassJoined:FireServer(player, "Officer")
Like Konjointed said before. You don’t need to send over the player value to the server. It’s preset.
So what you have, is your sending over 2 values.
There’s already 1 value in the server side, which is the player, because it automatically knows. So message is the 1st value you have set, which is the player. (Actual variable you sent over.) And your 3rd unmentioned value on the server side is the actual message. Remove the player from the FireServer part, and you should be good.
For some reason it isn’t getting past the
if type(message) == string then
part.
This is all the fire clients I have:
1: game.ReplicatedStorage.ClassJoined:FireServer("UK")
2: game.ReplicatedStorage.ClassJoined:FireServer("DE")
3: game.ReplicatedStorage.ClassJoined:FireServer("Officer")
Server part:
game.ReplicatedStorage.ClassJoined.OnServerEvent:Connect(function(player, message)
print("Event registered")
if type(message) == string then```
Just did some testing. Add quotes around string
, then it should work.
Here’s my testing code if you want to put it in the command executor.
print(type("Hi")) if type("Hi") == "string" then print("Yes") end
prints "Hi’ and “Yes”
Vs.
print(type("Hi")) if type("Hi") == string then print("Yes") end
Prints “Hi” but not yes.