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

I want make button that you click on button and you get hair but not luck. How to fix it?

Asked by
kiref81 -24
3 years ago

Code:

game.StarterGui.Menu.FemaleHair.TextButton4.MouseButton1Click:Connect(function()
local StarterCharacter = game.StarterPlayer.StarterCharacterScripts
local Hair4 = game.ReplicatedStorage.Hair.Hair4

StarterCharacter:GetChildren(Hair4)

end)    

1 answer

Log in to vote
0
Answered by 2 years ago

You shouldn't use StarterCharacter to store scripts because it replicates it to every character. You should use ServerStorage, and use WaitForChild() instead of GetChildren(). Also you can't access from starter gui. You will need to put the script in the gui to be able to access it. Aslo put the hair in server storage.

The reason it isn't working is because you are calling non existent values from the starter areas because you can't access stuff from there, and its just getting the children. It doesn't know what to do with the children.

script.Parent.MouseButton1Click:Connect(function()
    local gui= script:FindFirstAncestor("PlayerGui")
    if gui then
        local player = gui.Parent
        local Hair4 = game.ServerStorage.Hair4:Clone()
        --you need to clone the hair for the player--
        Hair4.Parent = Player.Character
    end
end)


if you want everyone to get hair

--server script in button--
local HairEvent = game.ReplicatedStorage.HairEvent
-- HairEvent is a remote event so it goes in ReplicatedStorage. this is to replicate it to every client--
script.Parent.MouseButton1Click:Connect(function()
    HairEvent:FireAllClients("Hair4")
    --fires to every players client--
end)

- - LocalScript in starterplayerscripts--
game.ReplicatedStorage.HairEvent.OnClientEvent:Connect(function(hairname)
    local gui= script:FindFirstAncestor("PlayerGui")
    if gui then
        local player = gui.Parent
        local Hair4 = game.ServerStorage:WaitForChild(hairname):Clone()
        --you need to clone the hair for the player--
        Hair4.Parent = Player.Character
    end
end)
Ad

Answer this question