#UI button works only one

1 messages · Page 1 of 1 (latest)

fiery nexus
#

Why does the button work only once? The RemoteEvent is fine and the server morph logic works every time. How can I make the button always fire the RemoteEvent, even after the player's Character has changed?
I have buttons in a ScreenGui that send a RemoteEvent to the server to morph the character.
It works the first time, but after the player morphs once (Character changes), clicking the button again does nothing—no print, no event sent.
The buttons themselves are still in the GUI; the LocalScript is not destroyed.

local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local buttonsFolder = playerGui:WaitForChild("MorphList"):WaitForChild("MorphFrame")
local eventsFolder = RS:WaitForChild("Events"):WaitForChild("Morph")
for _, button in ipairs(buttonsFolder:GetChildren()) do
if button:IsA("TextButton") then
local morphName = button.Name

    button.MouseButton1Click:Connect(function()
        local event = eventsFolder:FindFirstChild("Morph_" .. morphName)
        if event then
            event:FireServer(morphName)
            print("Morph 이벤트 전송:", morphName)
        else
            warn("RemoteEvent가 존재하지 않음:", morphName)
        end
    end)
end

end
player.CharacterAdded:Connect(function(newChar)
print("새 Character 감지됨:", newChar.Name)
end)

somber waspBOT
#

studio** You are now Level 1! **studio

fiery nexus
#

The humanoid actually gets replaced when morphing

sacred wigeon
#

idk

shy ferry
#

are you changing the character reference

fiery nexus
#

Keeping the server script the same and putting the local script under the UI makes it run fine, but when I moved it to the player script for optimization, it only runs once.

shy ferry
fiery nexus
#

No

shy ferry
#

it might not be finding the event

#

debug and see if event is nil

#

nvm

#

does it show the warning then

#

or js nothing at all

#

i would restart studio and rewrite the script if nothing shows

#

works sometimes as crazy as it sound

fiery nexus
#

Someone said I need to use "while"

#

Wait,do

modern mauve
#

Remove setting the morph name and just set the buttons name, then send the button name

#

Think your issue is boiling down to the local morph name being set constantly to the next button

#

Meaning no matter what buttons you select you getting the last one and assuming you have a server sainty check in place, you're not morphing because you already have that morph

turbid wagon
somber waspBOT
#

studio** You are now Level 3! **studio

fiery nexus
#

Each Morph has a different event name, and there is only one server script and one local script, so the UI distinguishes events by the Morph name.

#

Remote event's name is Moprh_(morph name)

turbid wagon
fiery nexus
turbid wagon
#

i would rewrite this script and put it under startergui

fiery nexus
#

ok

turbid wagon
#

also there is no need to Player.CharacterAdded in a local script

#

and use functions

#

and .Activated for buttons instead of MouseButton1