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

How do I make this script work in-game instead of just in Studio's Play for an obby?

Asked by
camxd01 48
8 years ago

My friend and I are making a game that has an obby you get to from the lobby for people waiting. The problem is that it won't teleport them back to the lobby and reward them. [IMPORTANT] It works in ROBLOX Studio's "Play". It is a script as a child of a part directly in workspace. I have tried it under a local script in the same location but it still won't work when you play outside of studio.

The script is...

--Made by CamScripted
function onTouched(part)
local shillings = game.Players.LocalPlayer.leaderstats.Shillings
local c = part.Parent
if c ~= nil then
c.Torso.CFrame = CFrame.new(Vector3.new(19.808, 3.285, 8.748))
end
wait(.1)
shillings.Value = shillings.Value + 10
wait(1)
end
script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
3
Answered by 8 years ago

When using LocalPlayer it has to be in a LocalScript, inside a player object or character. To fix this, you just need to check if what touched the part was a player's character and not just any random block. Here's the code you'd need:

--Made by CamScripted, edited by UndeniableLimited :3
function onTouched(part)
local shillings -- Create it here so it can be used later
local c = part.Parent
if c ~= nil and game.Players:FindFirstChild(c.Name) ~= nil then -- If they're a player
shillings = game.Players[c.Name].leaderstats.Shillings
c.Torso.CFrame = CFrame.new(19.808, 3.285, 8.748) -- Why Vector3 in a CFrame? It's not needed
end
wait(.1)
shillings.Value = shillings.Value + 10
-- Removed a wait from here, it wasn't needed unless you were going to add to it!
end
script.Parent.Touched:connect(onTouched)
0
Thanks for the help ;3 camxd01 48 — 8y
0
If I put it under some part of the character it wouldn't connect to the end of the obby. How do I put it there and it still register the part they are supposed to touch? camxd01 48 — 8y
Ad

Answer this question