I have a local script in ImageButton to fire server:
local button = script.Parent local requestMakeup = game.ReplicatedStorage.MakeupRequest
local function onButtonClicked() requestMakeup:FireServer("darkgalaxy") end
button.MouseButton1Click:Connect(onButtonClicked)
And a script in ServerScriptService: local requestMakeup = game.ReplicatedStorage.MakeupRequest
local items = { darkgalaxy = "rbxassetid://1376206152",
}
local function onRequestEvent(player, itemName) local itemId = items[itemName] local p = game.Players.LocalPlayer.Name if not workspace:WaitForChild(p) then return end local h = workspace:WaitForChild(p).Humanoid if (h ~= nil) then if game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name) ~= nil then h.Parent.Head.face.Texture = itemId print"Face change!" end end end
requestMakeup.OnServerEvent:Connect(onRequestEvent)
I have shortened the item list to just one item but all else is same. This works fine in studio and "Face change" prints to output but will not work in game. Where have I gone wrong? Any help much appreciated. Thank you
The answer is simple. You can't do localplayer outside of a local script. Anyways i fixed the entire script for you here it is
local button = script.Parent local requestMakeup = game.ReplicatedStorage.MakeupRequest script.Parent.MouseButton1Click:connect(function() requestMakeup:FireServer(game.Players.LocalPlayer.Name, "darkgalaxy") end)
-And the script in serverscriptservice
local requestMakeup = game.ReplicatedStorage.MakeupRequest local items = { darkgalaxy = "rbxassetid://1376206152", } requestMakeup.OnServerEvent:connect(function(player, itemName, itemName) print("Fired") print(itemName) local itemId = items[itemName] print(itemId) local plr = player local humanoid = plr.Character:WaitForChild('Humanoid') print(player) plr.Character.Head.face.Texture = itemId print("Changed Face") end)