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

Why doesn't the store script in my car spawning system work?

I am trying to make a surface GUI which spawns you a car in. I also need it to deduct money from the player's leaderstat. It worked before i added the money system and now when i do have the money system doesn't work Code: (in a script)

local clone = game.ReplicatedStorage.Trodent610

backup = clone:Clone()

function click(player)

local stats = player:FindFirstChild('leaderstats')

if not stats then return end

local Money = stats:FindFirstChild('Money')

if not Money then return end

if Money.Value >= 100 then

script.Parent.Text="Your car is spawning!"

script.Parent.Visible = false

clone=backup:clone()

clone.Parent=game.Workspace

clone:makeJoints()

Money.Value = Money.Value - 100

wait(10)

script.Parent.Text="Trodent 610"

script.Parent.Visible = true

end

  

end

  

script.Parent.MouseButton1Click:Connect(click)

This is the error it brings up: Workspace.spawnst.SurfaceGui.trodent.Script:4: attempt to index local 'player' (a nil value)

1 answer

Reason why it's not working is that the way your having the click detected doesn't return what player it has. Since your using a UI, when it's clicked it's not known what player clicks it.

A possible solution to fix this would be to make the click detector a local script that fires a remote event to try to respawn the car.

Example:

-- SERVER SCRIPT

local remoteEvent = Instance.new("RemoteEvent",script.Parent)

function click(player)
    -- Your code here
end

remoteEvent.OnServerEvent:Connect(click)	

-------------------------------------------------
-- LOCAL SCRIPT

local remoteEvent = script.Parent:WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function() 
    remoteEvent:FireServer()
end

3 comments

0

Alright, ill try that out!

0

Unfortunately, it did not work.

0

Keep in mind, the scripts are in a TextLabel and its a SurfaceGUI

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