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

Why don't these scripts work in an actual server? They work in offline mode. I need an answer quick

I have these scripts that don't work in actual servers. They work when I go in test mode in the studio. Script 1:

script.Parent.Touched:connect(function(hit)
script.Parent.Transparency = 1
script.Parent.Parent.Gold1.Transparency = 1
script.Parent.Parent.Gold2.Transparency = 1
script.Parent.Parent.Chest.Transparency = 1
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
	game.Players.LocalPlayer.leaderstats.Beli.Value = game.Players.LocalPlayer.leaderstats.Beli.Value + 6
	game.Players.LocalPlayer.leaderstats.Bounty.Value = game.Players.LocalPlayer.leaderstats.Bounty.Value + 14
	wait()
end
wait()
script.Parent.Transparency = 0
script.Parent.Parent.Chest.Transparency = 0
script.Parent.Parent.Gold1.Transparency = 0
script.Parent.Parent.Gold2.Transparency = 0
wait()
script.Parent.Parent.Coverer.CanCollide = true
script.Parent.Parent.Coverer.Transparency = 0
wait(30)
script.Parent.Parent.Coverer.Transparency = 1
script.Parent.Parent.Coverer.CanCollide = false
end)
-- Ik I got too many parents but its still fine

Script 2:

script.Parent.MouseClick:connect(function()
wait()
if game.Players.LocalPlayer.leaderstats.Beli.Value >= 50 then
game.Players.LocalPlayer.leaderstats.Beli.Value = game.Players.LocalPlayer.leaderstats.Beli.Value - 50
script.Parent.Parent.Transparency = 1
wait()
script.Parent.Parent.CanCollide = false
wait(2.5)
script.Parent.Parent.Transparency = 0
wait()
script.Parent.Parent.CanCollide = true
print("Bought")
else
print("Not enough Beli")
end
end)
-- 2 many parents again, but it works in offline mode

Please answer?

4 comments

0

Are these both LocalScripts? LocalPlayer is only accessible in live servers from LocalScripts.

0

No, normal scripts.

0

I tried them with a local script, and it still didn't work.

0

You can only access "LocalPlayer" in LocalScripts, and LocalScripts don't run in Workspace. You're going to have to make some large edits so you can get the player correctly.

1 answer

✓ Accepted answer

Well, the edits to be made aren't so major. As said by Discern and AdarkTheScoundrel, LocalPlayer can only be accessed from LocalScripts in a descendant of the Player. You don't exactly need to use a LocalScript.

-- I've decided to make variables as seeing 'script.Parent' a lot throughout the script is a bit messy.
Gold1 = script.Parent.Parent.Gold1
Gold2 = script.Parent.Parent.Gold2
Chest = script.Parent.Parent.Chest
Coverer = script.Parent.Parent.Coverer

script.Parent.Touched:connect(function(hit)
	if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
		p = game.Players:GetPlayerFromCharacter(hit.Parent)
		Gold1.Transparency = 1
		Gold2.Transparency = 1
		Chest.Transparency = 1
		p.leaderstats.Beli.Value = p.leaderstats.Beli.Value + 6
		p.leaderstats.Bounty.Value = p.leaderstats.Bounty.Value + 14
		script.Parent.Transparency = 0
		Chest.Transparency = 0
		Gold1.Transparency = 0
		Gold2.Transparency = 0
		Coverer.CanCollide = true
		Coverer.Transparency = 0
		wait(30)
		Coverer.Transparency = 1
		Coverer.CanCollide = false
	end
end)

Considering Script2 was going to be used for a ClickDetector..

script.Parent.MouseClick:connect(function(p) -- If you put a parameter, it defines the player (ClickDetectors)
	wait() -- Not necessary
	if (p.leaderstats.Beli.Value >= 50) then
		p.leaderstats.Beli.Value = p.leaderstats.Beli.Value - 50
		script.Parent.Parent.Transparency = 1
		wait()
		script.Parent.Parent.CanCollide = false
		wait(2.5)
		script.Parent.Parent.Transparency = 0
		wait()
		script.Parent.Parent.CanCollide = true
		print("Bought")
	else
		print("Not enough Beli")
	end
end)

2 comments

0

Thanks!

0

Glad I could help!

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