Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why do my face scripts using remote events not work out of Studio?

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

2 comments

0

LocalPlayer does not work in server scripts.

0

Thank you :)

1 answer

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

  • The localscript
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)

1 comment

0

Thank you so much, i am very new to programming and keen to learn. I thought I had covered everything when I was trying to fix this myself but had not considered the localplayer in script. I knew it would be something really simple hehe so glad to have this help :)

This discussion is preserved as it was. New answers, comments, and votes are closed.