So I'm making a musket game that will consist of a GUI that will change class. (E.g. infantry, officer, rifles.) Below is a local script inside a screenGUI.
local ChangeFrame = script.Parent:WaitForChild("ChangeFrame") local ChangeClassButton = script.Parent:WaitForChild("ChangeClassButton") local OfficerEvent = game.ReplicatedStorage:WaitForChild("OfficerEvent") local RiflesEvent = game.ReplicatedStorage:WaitForChild("RiflesEvent") local Officer = script.Parent:WaitForChild("OfficerButton") local Rifles = script.Parent:WaitForChild("RiflesButton") -- ChangeClassButton.MouseButton1Click:Connect(function() ChangeFrame:TweenPosition(UDim2.new(0.5, 0,0.5, 0)) end) Officer.MouseButton1Click:Connect(function() OfficerEvent:FireServer() end) Rifles.MouseButton1Click:Connect(function() end)
Below is a normal server script stored inside ServerScriptService.
local player = game.Players local character = game.Players.Character game.ReplicatedStorage.OfficerEvent.OnServerEvent:Connect(function() character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://1422626514" character:WaitForChild("Pants").PantsTemplate = "rbxassetid://1070344465" player.Character.Humanoid.Health = 0 end)
The whole purpose of these scripts is to make so when you click a TextButton for officer class, your character will die, and then get your shirt changed into the officer uniform. It doesn't work. Any help please?
You are setting the variable "players" to game.Players
, which is just a service.
Try this:
game.ReplicatedStorage.OfficerEvent.OnServerEvent:Connect(function(player) local character = player.Character character:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://1422626514" character:WaitForChild("Pants").PantsTemplate = "rbxassetid://1070344465" player.Character.Humanoid.Health = 0 end)