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

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

Asked by 6 years ago

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

0
LocalPlayer does not work in server scripts. User#20279 0 — 6y
0
Thank you :) nineinchnerd 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)

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 :) nineinchnerd 0 — 6y
Ad

Answer this question