What are you attempting to achieve? (Keep it simple and clear)
I am attempting to give the player a house when they touch the door if they have enough money and they don’t already have a house.
What is the issue? (Keep it simple and clear - Include screenshots/videos/GIFs if possible)
The script is not outputting any errors, and the script is not changing any values even if the player’s balance is above or equal to 175.
What solutions have you tried so far? (Have you searched for solutions through the Roblox Wiki yet?)
I have tried:
Removing the player defined with local and using PlayerAdded.
Removing “if player then” from the script.
--// OldBo5 \\--
game.Players.PlayerAdded:Connect(function(player)
script.Parent.Touched:Connect(function(hit)
if player then
if player.leaderstats.Money.Value >= 175 and script.Parent.Parent.Parent.Parent.Parent.houseOwner.Value == nil and script.Parent.Parent.Parent.Parent.Parent.isBought.Value == false then
script.Parent.Parent.Parent.Parent.Parent.houseOwner.Value = player.Name
script.Parent.Parent.Parent.Parent.Parent.isBought.Value = true
script.Parent.Parent.Name = "Home Owner: "..player.Name
player.leaderstats.Money.Value = player.leaderstats.Money.Value - 175
end
end
end)
end)
You don’t need a PlayerAdded function. Just do a Touched event, and get the player by its character:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then -- checks if the thing that touched it has a humanoid
local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- gets the player from the character
if player.leaderstats.Money.Value >= 175 and script.Parent.Parent.Parent.Parent.Parent.houseOwner.Value == nil and script.Parent.Parent.Parent.Parent.Parent.isBought.Value == false then
script.Parent.Parent.Parent.Parent.Parent.houseOwner.Value = player.Name
script.Parent.Parent.Parent.Parent.Parent.isBought.Value = true
script.Parent.Parent.Name = "Home Owner: "..player.Name
player.leaderstats.Money.Value = player.leaderstats.Money.Value - 175
end
end
end)
Don’t hesitate to let me know if you have any issues! (:
Alright, will try! Edit: Looks like it quits working at Line 10.
script.Parent.Touched:Connect(function(hit)
print("Line 1")
if hit.Parent:FindFirstChild("Humanoid") then -- checks if the thing that touched it has a humanoid
print("Line 2")
local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- gets the player from the character
print("Line 3")
if player.leaderstats.Money.Value >= 175 and script.Parent.Parent.Parent.Parent.Parent.houseOwner.Value == nil and script.Parent.Parent.Parent.Parent.Parent.isBought.Value == false then
print("Line 4")
script.Parent.Parent.Parent.Parent.Parent.houseOwner.Value = player.Name
print("Line 5")
script.Parent.Parent.Parent.Parent.Parent.isBought.Value = true
print("Line 6")
script.Parent.Parent.Name = "Home Owner: "..player.Name
print("Line 7")
player.leaderstats.Money.Value = player.leaderstats.Money.Value - 175
print("Line 8")
end print("Line 9")
end print("Line 10")
end) print("Line 11")