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

How do I fix this inprescise error? "attempt to call a nil value"

11:02:58.058 - attempt to call a nil value (x2)

I've used print to determine which script this is in.

LocalScript (1)

local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
	 
function leftClick()
	local existp = playerGui.OrderGui.Naem.TBO.Text
	game.ReplicatedStorage.MilkshakeVanilla:FireServer(existp)
	 print("VanillaClick")
	
end 


script.Parent.MouseButton1Click:Connect(leftClick)

Script

game.ReplicatedStorage.MilkshakeVanilla.OnServerEvent:Connect(function(plr,existp)
	print ("serverscript")
	game.Workspace.Functions.WhoOrdered.Value = existp
	game.ReplicatedStorage.MilkshakeVanilla2:FireAllClients()
	print ("fired all clients")
end)

LocalScript (2), the one with the error. It does NOT print "game," nor do anything further in the script

game.ReplicatedStorage.MilkshakeVanilla2.OnClientEvent:Connect()
	print ("game")
	print(game.Workspace.Functions.WhoOrdered.Value)
	local existp = game.Workspace.Functions.WhoOrdered.Value
	script.Parent.Text = "Vanilla Milkshake by 2ndlocal "..existp
	print ("got milkshakevanilla2")
	print (existp)

So... any reccomendations?

4 comments

0

The code is malformed...? Where is your function callback?

0

I don't have any.

0

So what is line 1 in your last snippet? It's a blank :Connect()?

0

Yes, it is a blank connect..?

1 answer

Improvements 2nd local script

Use GetService Add a parameter on line 1 near :Connect()


local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local player = Players.LocalPlayer
local welcomePlayerEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

local function onPlayerAdded(player)
	welcomePlayerEvent:FireClient(player)
end
 Players.PlayerAdded:Connect(onPlayerAdded)
 
--LocalScript 
 

local function onWelcomePlayerFired()
	print ( "It works")
end

 
welcomePlayerEvent.OnClientEvent:Connect(MilkshakeVanilla2)

2 comments

0

What does this do?

0

This fires when a player has joined the game make sure this in a local script.

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