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

Why does the server script can't detect the helmet model in the character but the Local Script can?

Asked by 5 years ago
Edited 5 years ago

So basically I am adding a function light on my helmet. To do so when pressed L key it fire an event which enable the light on the server (in theory)

local meep = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer

function keypress(actionName, inputState, inputObj)
    if inputState == Enum.UserInputState.Begin then
    if player.Character.Helmet:FindFirstChild("HelmetLight") then
        game.ReplicatedStorage.HelmetLight:FireServer()
        end
    end
end


game.ContextActionService:BindAction("BoundAction", keypress, false, Enum.KeyCode.L)

This is the local script.

local ReplicatedStorage = game:GetService("ReplicatedStorage")


game.ReplicatedStorage.HelmetLight.OnServerEvent:connect(function(player)
    print(player.Name)
    if player.Character.Helmet.HelmetLight.Light.L1.Enabled == false then
        print("hello there")
        player.Character.Helmet.HelmetLight.Light.L1.Enabled = true
        player.Character.Helmet.HelmetLight.Light.L2.Enabled = true
    else
        print("bye there")
        player.Character.Helmet.HelmetLight.Light.L1.Enabled = false
        player.Character.Helmet.HelmetLight.Light.L2.Enabled = false
    end
end)

This is the server script. Everything is fine until there. The server script give me this error:

23:32:13.589 - Helmet is not a valid member of Model 23:32:13.590 - Stack Begin 23:32:13.590 - Script 'ServerScriptService.HelmetLight', Line 9 23:32:13.590 - Stack End

No idea why it does that. Any idea?

0
try adding a local HelmetLight = player.Character.HelmetFindFirstChild("HelmetLight") then doing ``if HelmetLight then code end`` DragonSkyye 517 — 5y
0
the other theory could be because you cloned, or created the `HelmetLight` inside a localscript to the player, which makes the HelmetLight local not serversided DragonSkyye 517 — 5y
0
FindFirstChild just stops the script since it ain't found. anthonypjo 5 — 5y
0
I believe I found the problem, it didn't exist at all, the way I tested the script was throught the "test play". Once testing in a proper server, it worked. I think its because the "test play" server made my helmet local and not serversided like you said. anthonypjo 5 — 5y
0
I diden't really look into the code at all but it could be because the helmet was added in a local script, probably not the case tho. danglt 185 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Didn't test properly, in "test play" the helmet was only on the client, unlike in a proper server, which explain why the server script couldn't find the helmet.

Ad

Answer this question