I’m trying to make a click detector that only works if a play has a key. Ive set up print statements to test out the scripts and the print statement that runs when a player doesnt have a key runs, even though I have it equipped. There are 2 scripts that talk to eachother via remote event. 1 is a local in scs and the other is a serverscript parented to the part that also has the clickdetector.
local:
local player = game.Players.LocalPlayer
local tool = player:FindFirstChild('Reactorkey') or player.Character:FindFirstChild("Reactorkey")
local event = game.ReplicatedStorage["Reactor Events"].Key
if tool then
print("if works")
event:FireServer()
else
print("Else Works")
print("no key!")
end
Server
local clickDetector = script.Parent.Click
local event = game.ReplicatedStorage["Reactor Events"].Key
function eee()
function onMouseClick()
print("IT WORKS LES GOOOOO")
end
end
clickDetector.MouseClick:connect(onMouseClick)
event.OnServerEvent:Connect(eee)
There are no errors in the output and else works and no key prints. Nothing else prints.
Thanks.
Ok so the local script is working now. But i get the error message in the server script stating: attempt to call a nil value. When I click the error message it doesnt do anything.
A RemoteEvent isn’t needed for this(and the tool check was done on the client which exploiters are able to bypass):
clickDetector.MouseClick:Connect(function(player)
--I assume you meant player.Backpack?
local tool = player.Backpack:FindFirstChild("Reactorkey") or player.Character:FindFirstChild("Reactorkey")
if tool then
print(player.Name.." has key")
else
print(player.Name.." doesn't have key")
end
end)
And the reason the old script wasn’t working was because MouseClick:Connect(onMouseClick) runs before the onMouseClick function is defined causing it to error(the eee function must run to make the onMouseClick function not equal to nil).