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

Target is a nil value? Remote Event/LocalScript Error???

So I am creating handcuffs for a game, but of course ): I have run into a problem. You see I send info to a server script via a remote event with the argument 'target' (player, target). But it does not seem to be working.

ServerScript:

local Resources = script.Parent.Resource.Instances
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ArrestEvent = ReplicatedStorage.Events:WaitForChild("Arrest")
local ReleaseEvent = ReplicatedStorage.Events:WaitForChild("Release")
local CaptureEvent = Resources:WaitForChild("Capture")

CaptureEvent.OnServerEvent:Connect(function(player,target)
	local t = target
	if t.Humanoid then
		local h = t.Humanoid
		h.WalkSpeed = 0
		h.JumpPower = 0
		wait()
		h.PlatformStand = true
	end
end)

ArrestEvent.OnServerEvent:Connect(function(player,target)
	local t = target
	if t.TeamColor ~= BrickColor.new("Really red") then
		t.TeamColor = BrickColor.new("Really red")
		t.Humanoid.Health = 0
	end
end)

ReleaseEvent.OnServerEvent:Connect(function(player,target)
	local t = target
	if t.Humanoid then
		local h = t.Humanoid
		h.WalkSpeed = 16
		h.JumpPower = 50
		wait()
		h.PlatformStand = false
	end
end)

LocalScript 1: Place UI (Working) :

local Resources = script.Parent.Resource.Instances
local Event = Resources:WaitForChild("Capture")
local Handle = script.Parent:WaitForChild("Handle")
local UI = Resources:WaitForChild("UI").ArrestGUI
local Player = game.Players.LocalPlayer
local Debounce = false

if game:GetService("Teams") == nil then
	error("Cannot run the script without the teams' service.")
end

Handle.Touched:Connect(function(obj)
	if not Debounce then Debounce = true
		if obj.Parent:FindFirstChild("HumanoidRootPart") then
			local torso = obj.Parent:FindFirstChild("Torso")
			if torso then
				local target = torso.Parent.Name
				wait()
				print(target)
				Event:FireServer(target)
				wait()
				UI.Parent = Player.PlayerGui
				UI.MainFrame.View.Target.Value = ""..target
				UI.MainFrame.View.Player.Image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=150&y=150&Format=Png&username="..target
				wait(1)
				Debounce = false
			end
		end
	end
end)

LocalScript 2: Fire Arrest/Release Remotes (Broken :():

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ArrestEvent = ReplicatedStorage.Events:WaitForChild("Arrest")
local ReleaseEvent = ReplicatedStorage.Events:WaitForChild("Release")
local Arrest = script.Parent:WaitForChild("Arrest")
local Release = script.Parent:WaitForChild("Release")
local Target = script.Parent:WaitForChild("Target").Value

Arrest.MouseButton1Click:Connect(function()
	if Target ~= nil then
		local target = game.Players:FindFirstChild(Target)
		print(target)
		ArrestEvent:FireServer(target)
	else
		return warn("> Got input, 'Arrest'. Target(user) is nil.")
	end
end)

Release.MouseButton1Click:Connect(function()
	if Target ~= nil then
		local target = game.Players:FindFirstChild(Target)
		print(target)
		ReleaseEvent:FireServer(target)
	else
		return warn("> Got input, 'Release'. Target(user) is nil.")
	end
end)

4 comments

0

Why is your event listener returning a value

1

Because it's wants to.

1

bc it doesnt want to feel left out

0

Thank you

1 answer

I believe using a RemoteFunction is the best approach since you're getting some value from the client.

local RF = game.ReplicatedStorage.RemoteFunction

RF.OnServerInvoke = function()
	--code
end

Then do fire is..

local RF = game.ReplicatedStorage.RemoteFunction

RF:InvokeServer(arg)

Now, it's the same as RemoteEvents, just the way the statement starts is different.

2 comments

0

I've made a handcuff and I knew what the problem was after, so if this doesn't work then please let me know via. DMs or responding back here. Error information would be greatly appreciated.

0

This doesn't work sadly ): The error information is the same "t is a nil value"

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