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

Remote Events with two scripts not working Whats wrong with my remote events not working?

My remote event script isn't working. I am trying to do: When the player picks up a tool a variable is changed stating that the player has picked up the tool.

First script: (Local Script)

local tool = script.Parent.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")


--Remote Events Variables


tool.Equipped:Connect(function()
	wait()
	humanoid.Health = 100
	if game.SoundService.GlobalToolKey.Value == script.Parent.ToolKey.Value then -- safety key
		game.ReplicatedStorage.RemoteEvents.HolderOn:FireServer()
		--PLAYER HAS PICKED UP THE ITEM
		
	else -- If the tool's key doesn't match the global one: (Kicking the player)
		script.Parent.Parent:Destroy()
		game.Players.LocalPlayer:Kick(" We know you are hacking you little dandelion.")
	end
	
end)
	 

tool.AncestryChanged:Connect(function()
	--ITEM WAS DROPPED
	game.ReplicatedStorage.RemoteEvents.HolderOff:FireServer() ---
	print("Picked up")
end)
print("LastCheck")

humanoid.Changed:Connect(function()
	if humanoid.Health == 0 then
		game.ReplicatedStorage.RemoteEvents.HolderOff:FireServer() ---
		print("Item dropped || Player Died")
		--PLAYER HAS DROPPED THE ITEM
	end
end)

tool.Unequipped:Connect(function()
	wait()
	humanoid.Health = 100
	--PLAYER HAS DONE NOTHING JUST UNEQUIPPED	

end)

Second Script: (Normal Script)

local function ItemPickedUp()
	print("Item picked up!")
	script.Parent.Value = true
end

game.ReplicatedStorage.RemoteEvents.HolderOn.OnServerEvent(ItemPickedUp)

If you need more info feel free to ask me.

1 answer

Ah, new scripters with remote events, my favorite to answer!

It is a simple and easy fix, the easiest way to fix this is:

Because for some reason, you must have plr in the remoteevent function sad

local function ItemPickedUp(plr)
    print("Item picked up!")
    script.Parent.Value = true
end

game.ReplicatedStorage.RemoteEvents.HolderOn.OnServerEvent:Connect(ItemPickedUp)

Please accept this as the answer if it helped!

ADVICE TIME!!

I would recommend using thing.EventNameHere:Connect(function(--[[args here]]) because it may shorten code and make it look cleaner

just some code, i recommend using this instead of the code above

game.ReplicatedStorage.RemoteEvents.HolderOn.OnServerEvent:Connect(plr)
	print("Item picked up!")
    	script.Parent.Value = true
end)

1 comment

0

It still doesn't work...?

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