Hello, I am KDBgames and I need your help.
I was scripting a Buy button to buy a house. But, not in the GUI. I want it in the Workspace. So I started scripting. I first tryed a “LocalScript”. But I saw that that do not worked. So I tryed the same script in a normal “Script”. And it worked!
But the problem is. I can’t find the “player”. You can see what I have in the screens/codes:
-- This is the code for the "Script" in the button.
local player = game.Players.LocalPlayer
local Parent = script.Parent.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:Connect(function()
print(player)
print("Click")
if Parent.Owner.Value == "" then
print("Boughed")
Parent.Owner.Value = player.Name
Parent.Using.Value = true
player.leaderstats.Money.Value = player.leaderstats.Money.Value - Parent.Price.Value
else
if player.Name == Parent.Owner.Value then
print("Selled")
Parent.Owner.Value = ""
Parent.Using.Value = false
player.leaderstats.Money.Value = player.leaderstats.Money.Value + (Parent.Price.Value / 2)
end
end
end)
-- This is what I get back.
nil
Click
Boughed
11:04:20.566 - Workspace.Test House Scripts.BuyBoard.Board.SurfaceGui.Frame.BuyButton.Script:9: attempt to index nil with 'Name'
11:04:20.569 - Stack Begin
11:04:20.571 - Script 'Workspace.Test House Scripts.BuyBoard.Board.SurfaceGui.Frame.BuyButton.Script', Line 9
11:04:20.577 - Stack End
This is the Button in the Workspace:
This is where it is in the Explore:
So the problem is that I can’t find the player.
If you can help me. Please do it! I really need your help!
Thanks for reply.