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

Giving money from a pad and teleporting error?

It's supposed to teleport the user to the lobby spawn and give them 35 points. Everything is set in order so there should not be a problem. Absolutely nothing happens when i step on it.

This is for the local player that steps on it.

Also i checked it's not any grammar errors with the leaderboard and points

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

ERROR

14:31:10.026 - Workspace.Platform Run.Money!.Script:5: attempt to index global 'player' (a nil value)

Script

enabled = true
player = game.Players.LocalPlayer

script.Parent.Touched:connect(function(hit)
	local leaderstats = player:FindFirstChild("leaderstats")
	local points = leaderstats:FindFirstChild("points")
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	if Humanoid and enabled then
	points.Value = points.Value + 35
	hit.Parent:MoveTo(game.Workspace.LobbySpawn.Position)
	wait(0.5)
	enabled = false
	wait(1)
	enabled = true
	end
end)

4 comments

0

put it in code blocks

0

Local Script or server script?

0

Local script

2 answers

I can happen to read LUA with code blocks, it's something I do & are used to, I figured out what was wrong.

You never defined what "player" was.

YOU ALSO should NEVER use a localscript to teleport players! Unless it is a global script then you should NEVER use LocalPlayer in a global script, it'll never work!

Part That Gets Touched (MUST BE NORMAL, INSIDE PART)

local Players = game.Players
local enabled = true
script.Parent.Touched:connect(function(hit)
	if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") then
		for i,v in pairs(Players:GetChildren()) do
			if v.Name == hit.Parent.Name then
				plrobj = v -- The player inside "Players"
				local points = plrobj.Leaderboard:FindFirstChild("points")
				if enabled == true then
					hit.Parent:MoveTo(game.Workspace.LobbySpawn.Position)
					points.Value = points.Value + 35
					enabled = false
					wait(1)
					enabled = true
				end
			end
		wait()
		end
	end
end)

I assume "enabled" is some debounce, so I reordered it.

And you never actually needed a local script, just that script above should do!

Essentially upon getting hit, the script first figures out if the thing that hit it, if its parent is a model. When it figures out it's a model, it checks if it's a humanoid. Once it figures out it's a humanoid, it iterates over players to see if it's a player or NPC. When it finds out it's a player, it gets points from the Player and if enabled is true, it adds them and teleports the player.

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