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

Can you help with my Teleportation Problem?

I've got this script which gives me a point and teleports me. This script works in studio but not online. When I test it online it just gives me points not teleport. So how would i fix this? Also its not a localscript.

debounce = false
win = 1
money = 15
function onTouched(part)
	if debounce == false then
		debounce = true
		local humanoid = part.Parent:findFirstChild("Humanoid")
		if (humanoid~=nil) then
		local thisplr = game.Players:findFirstChild(humanoid.Parent.Name)
		if (thisplr~=nil) then
			local stats = thisplr:findFirstChild("leaderstats")
			if (stats~=nil) then
				local score = stats:findFirstChild("Wins")
				local score2 = stats:findFirstChild("Money")
				if (score~=nil) then
					score.Value = score.Value + win
				if (score2~=nil) then
					score2.Value = score2.Value + money
					local character = game.Players.LocalPlayer.Name
					local torso = part.Parent:findFirstChild("Torso")
					torso.CFrame = game.Workspace.SpawnLocation.CFrame + Vector3.new(0,10,0)
					wait(0.6)
					debounce = false
				end
				
					
				end
			end
		end
		end
		elseif debounce == true then
			print("no")
			debounce = false
	end

end
script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer
  • Using :GetPlayerFromCharacter() First thing I saw, was since you are getting the player from whomever touched the part, you don't want to use game.Players:findFirstChild(humanoid.Parent.Name) Instead use :GetPlayerFromCharacter(part.Parent)

  • Using :WaitForChild() Another thing you should do, is when you are getting something as a variable, you should use :WaitForChild() instead of :FindFirstChild()

  • Problem The thing that ended up causing the script to stop working though (or what I believe) is that you said it wasn't a LocalScript yet you used LocalPlayer on line 19. You can't use LocalPlayer in serverside scripts. I got rid of this line, and just used player.Character to get the torso, as player was already found from using the :GetPlayerFromCharacter event.

debounce = false
win = 1
money = 15

function onTouched(part)
	if debounce == false then
		debounce = true
		local player = game.Player:GetPlayerFromCharacter(part.Parent)
		if player then
			local stats = player:WaitForChild("leaderstats")
			if stats then
				local score = stats:WaitForChild("Wins")
				local score2 = stats:WaitForChild("Money")
				if score then
					score.Value = score.Value + win
					if score2~=nil then
						score2.Value = score2.Value + money
						local torso = player.Character:WaitForChild("Torso")
						torso.CFrame = game.Workspace.SpawnLocation.CFrame + Vector3.new(0,10,0)
						wait(0.6)
						debounce = false
					end
				end
			end
		end
	end
	elseif debounce == true then
		print("no")
		debounce = false
	end
end

script.Parent.Touched:connect(onTouched)

I had to write this script without any idea if their were errors or where the script would stop working, print(), etc.

Please do not get mad, and downvote this answer if it does not work. Just reply back, tell me any errors, etc and I will fix the problem ASAP!

Hope this now works and please +1 and accept answer.

  • NinjoOnline

1 comment

0

Thank you for the reply, you took your time and effort into. But i just removed line 19 just like you did a while back. I willl upvote you.

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