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

StarterCharacter Name Change GUI Button not working, why?

Asked by
BryanFehr 133
4 years ago
Edited 4 years ago

Hello all, I am creating a sort of character GUI where when the button is pressed, the script calls for a model in the StarterPlayer called "StarterCharacter1", then changes the name of the model to "StarterCharacter", and kills the player so they respawn as said character. When this respawn happens, the script is also supposed to destroy the "Frame", which is "script.Parent.Parent:Destroy()" It doesn't seem to work, and Menu is underlined and it won't show up in my output as to why, so I am asking for help! Thanks!

local Menu = script.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()Menu.Visible = true
game.Players.LocalPlayer.Character.Humanoid.Health = 0
game.StarterPlayer.StarterCharacter1.Name = "StarterCharacter"
script.Parent.Parent:Destroy()
end)
0
Line 1 has a period at the end User#24403 69 — 4y
0
Okay, removed that. Sorry LOL, But it doesn't work even without that. BryanFehr 133 — 4y

1 answer

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

Okay, so, first of all, you can't access GUIs with a serverscript. Doing for example script.Parent.Parent.Text = "hi" doesn't do anything because the ServerScript can't change any properties of a player's GUI.

First, create a RemoteEvent to ReplicatedStorage. Call it anything but for now I'm going to call it "WhateverEvent1" because honestly I don't know what to call it. You can call it what you want. Just put it in ReplicatedStorage.

So, we have to use RemoteEvents. To fix it, we have to make a LocalScript. It's gonna be the same code, but we have to change some things. Again, this MUST be a LocalScript. It should look like this:

local Menu = script.Parent.Parent;
local event = game.ReplicatedStorage.WhateverEvent1; -- Change WhateverEvent1 to the event name you put, but if its called WhateverEvent1 then just leave it
script.Parent.MouseButton1Click:Connect(function()
Menu.Visible = true; -- Minor fixes to your script, too.
    event:FireServer();
    script.Parent.Parent:Destroy();
end);

This time, you have to put a regular Script. Put it in Workspace or wherever your original script was. Looks like this:

local event = game.ReplicatedStorage.WhateverEvent1 -- Same thing as last time
event.OnServerEvent:Connect(function(plr) -- The plr is the localplayer so you can access it here in a serverscript
    local char = plr.Character or plr.Character:Wait();
    char.Humanoid.Health = 0;
    game.StarterPlayer.StarterCharacter1.Name = "StarterCharacter";
end)

If you don't know what FilteringEnabled is, i highly recommend you to read this wiki. (If you wanna know more about RemoteEvents which are used in this script, read this wiki.)

Ad

Answer this question