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

Can anyone help me with the error a nil value?

So i did this: LocalScript:

local target = script.Parent.Parent.target.Value
local sended = false

function send()
	if sended == false then
		local timer = tonumber(script.Parent.Time.Text)
		sended = true
		game.ReplicatedStorage.JailPlayer:FireServer(timer, target)
	end
end



script.Parent.Send.MouseButton1Click:Connect(send)

script.Parent.Parent.target.Changed:Connect(function()
	sended = false
end)

ServerScript in SSS:

game.ReplicatedStorage.JailPlayer.OnServerEvent:Connect(function(timer, target)
	game.Players:FindFirstChild(target).JailTime.Value = timer	
end)

And the player up here is a nil value ;(

1 answer

First of all, there's no need to get the player using what you're doing.

When you use FireServer(), the player is already passed to the server script.

Example

LocalScript

local event = game:GetService("ReplicatedStorage").RemoteEvent
event:FireServer() 

ServerScript

local event = game:GetService("ReplicatedStorage").RemoteEvent
event.OnServerEvent:Connect(function(player) -- player is already defined
	
end

So to fix your problems, simply change your server script to the following. (LocalScript needs no change)

Server Script

game.ReplicatedStorage.JailPlayer.OnServerEvent:Connect(function(player,timer, target)
    local targetPlayer = game:GetService("Players")[target]
    targetPlayer.JailTime.Value = timer   
end)

9 comments

0

I note that but i want the target player but i got the target already from another script and there is a value where the playertarget is stored but i don't know how to get it back?

0

Let me edit my script.

0

Now it should work as long as target is the name of a player

0

I will try

0

It says that 300 is not a player and 300 is normally the timer it's so weird

0

Must be a part in your other script.

0

What do u mean?

0

add me on discord MaxDev_BE#8486

0

Will do.

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