So today I started to learn how to script. I thought of making something simple: A ball that gets deleted and gives you a point with a pop-up when you touch it. The ball:
Gets deleted
Gives you a point
Shows a pop-up
Is anyone able to give some advice? AFAIK, nothing past line 18 works.
Hi. In line 18, you compare Instance with number value. You need to remember count of points before adding them and compare it with new value. (I hope my english is not too bad)
I see. Thank you! Do you know how I’d fix that though? I’m not really sure how to make the game remember the amount of points.
Actually, since the pop-up occurs simultaneously as when the point is added and sphere is touched, I don’t think an if-statement is necessary. You could remove the if statement at line 18 I reckon. alternatively, you could use the .Changed event for the NumberValue which is fired whenever its value changes.
i added some more checks and removed the line 18 check since it would be trying to add 1 to a numbervalue instance which will cause the check to always return false. You can only add numbers to numbers. script:
local sphere = script.Parent
sphere.Touched:Connect(function(touch)
local character = touch.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local stats = player:FindFirstChild("Leaderstats")
if stats then
local points = stats:FindFirstChild("Points")
if points then
sphere:Destroy()
points.Value = points.Value + 1
local humanoid = character:FindFirstChild("Humanoid")
local head = character:FindFirstChild("Head")
if humanoid and head then
local pointPopup = Instance.new("BillboardGui")
pointPopup.Adornee = head
pointPopup.Size = UDim2.new(0, 100, 0, 50)
pointPopup.AlwaysOnTop = true
pointPopup.BackgroundTransparency = 1
local DisplaypointPopup = Instance.new("TextLabel")
DisplaypointPopup.Size = UDim2.new(1, 0, 1, 0)
DisplaypointPopup.TextScaled = true
DisplaypointPopup.Text = "+1"
DisplaypointPopup.TextColor3 = Color3.fromRGB(0,255,0)
DisplaypointPopup.TextStrokeTransparency = 0
DisplaypointPopup.TextStrokeColor3 = Color3.fromRGB(0,0,0)
DisplaypointPopup.Font = Enum.Font.FredokaOne
DisplaypointPopup.Parent = pointPopup
pointPopup.Parent = head
task.wait(1) -- task.wait is generally better than wait() because of accuracy
pointPopup:Destroy()
end
end
end
end
end)
correct me if im wrong
try removing
if points.Value == points+1 then
...
end
or change it to:
if points.Value == points.Value+1
ok here’s what i see wrong on line 18:
say i have 15 points and i touch the ball. i now have 16 points
after i gain the point, you’re checking if my points value is equal to itself plus 1
first of all, you’re adding an instance with a number. cmon man…
secondly, how can a number be equal to itself plus 1? that makes no sense?
basically, you’re checking if 16 = 17. (false)
Sorry I’ve only been scripting for a few hours so I still don’t know much about scripting. But thanks, I realised what it was saying now and the code has been fixed. What I was trying to do is see if there was an increase in points, and if there was then the ui would pop up. Didn’t catch on that it was looking for itself plus 1 lol
i might be too late
local sphere = script.Parent
sphere.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
if not humanoid or not player then
return
end
sphere:Destroy()
local leaderstats = player:FindFirstChild("leaderstats")
local points = leaderstats and leaderstats:FindFirstChild("Points")
if not points then return end
points.Value += 1
local head = character:FindFirstChild("Head")
if not head then return end
local pointPopup = Instance.new("BillboardGui")
pointPopup.Adornee = head
pointPopup.Size = UDim2.fromOffset(100, 100) -- same as Udim2.new(0, 100, 0, 100)
pointPopup.AlwaysOnTop = true
pointPopup.Parent = head
local displayPointPopup = Instance.new("TextLabel")
displayPointPopup.Size = UDim2.fromScale(1, 1) -- same as Udim2.new(1, 0, 1, 0)
displayPointPopup.BackgroundTransparency = 1
displayPointPopup.Text = "+1"
displayPointPopup.TextScaled = true
displayPointPopup.TextColor3 = Color3.fromRGB(0, 255, 0)
displayPointPopup.TextStrokeTransparency = 0
displayPointPopup.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
displayPointPopup.Font = Font.fromName("FredokaOne")
displayPointPopup.Parent = pointPopup
task.wait(1)
pointPopup:Destroy()
end)
ok glad it works now!
(mark your reply as solution please)
Thank you, will do. I don’t use the forums that much.