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

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

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?

5 comments

0

try adding a local HelmetLight = player.Character.HelmetFindFirstChild("HelmetLight") then doing if HelmetLight then code end

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

0

FindFirstChild just stops the script since it ain't found.

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.

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.

1 answer

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.

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