Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
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. Punsisky 7 — 4y
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. JoshGamingHQ1 43 — 4y
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 Punsisky 7 — 4y
0
Alright, I got it working now. Thanks. :) Punsisky 7 — 4y
0
no problem, glad I helped! JoshGamingHQ1 43 — 4y
Ad

Answer this question