I’m just trying to make a button that gives a Humanoid in the workspace a hat.
Picture of workspace: https://gyazo.com/440240e80939eec32a710b37cf0f813d
Edit: Does this function only work in server scripts?
local button = script.Parent
local char = workspace:WaitForChild("CharSelectDummy")
local function onButtonActivated()
local hum = char:WaitForChild("Humanoid")
local hat = workspace:WaitForChild("HatTest"):Clone() --Your hat name.
hum:AddAccessory(hat)
end
button.Activated:Connect(onButtonActivated)
The hat will only be given to the client as I presume you are using a local script. You must use remote events to have the work. Also, what is CharSelectDummy?
Figured that out, how do I pass a function from a local script to a server script using a remote function?
This tutorial I’m reading only shows how to run a function from a server script by invoking it from localscript?
Cause I wanna trigger this by a mouse click on a button frame.
Alright
Local Script parent being The text button:
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")
local textButton = script.Parent
textButton.MouseButton1Click:Connect(function()
remoteEvent:FireServer()
end)
Server Script parenting ServerScriptService:
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")
remoteEvent.OnServerEvent:Connect(function(player)
local char = workspace:WaitForChild("CharSelectDummy")
local hum = char:WaitForChild("Humanoid")
local hat = workspace:WaitForChild("HatTest"):Clone() --Your hat name.
hum:AddAccessory(hat)
end)
That should work
textButton.MouseButton1Click:Connect(function()
remoteEvent:FireServer(hat)
end)`
this part, you have “hat” in the argument, what is this? What kind of arguments does FireServer() take?
oops I accidentally left that in get rid of it and try now
edit: If it works mark my code as Solution so I know
If Local Script where is the script located?