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

Why isn't my shooting game change class GUI script not working?

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?

1 answer

✓ Accepted answer

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)

5 comments

0

Well, I don't know if that works. But as you can see in the local script, my ChangeClass text button doesn't seem to work somehow. I clicked it, and the class frame doesn't appear.

0

OK, I tried replicating the situation. I copied your scripts, and the GUI appears for me. I'm kind of confused on your situation.

0

This video is about me experiencing the issue. It's easier to understand. https://www.youtube.com/watch?v=gVejnUsu_m8&feature=youtu.be

0

Alright, I got it working now. Thanks. :)

0

no problem, glad I helped!

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