Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can anyone help me with the error a nil value?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
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? MaxDev_BE 55 — 5y
0
Let me edit my script. MythicalShade 420 — 5y
0
Now it should work as long as target is the name of a player MythicalShade 420 — 5y
0
I will try MaxDev_BE 55 — 5y
View all comments (5 more)
0
It says that 300 is not a player and 300 is normally the timer it's so weird MaxDev_BE 55 — 5y
0
Must be a part in your other script. MythicalShade 420 — 5y
0
What do u mean? MaxDev_BE 55 — 5y
0
add me on discord MaxDev_BE#8486 MaxDev_BE 55 — 5y
0
Will do. MythicalShade 420 — 5y
Ad

Answer this question