generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Attempt to compare number with userdata error?

Previous Thread :: Next Thread 
Plutoeros is not online. Plutoeros
Joined: 13 Feb 2016
Total Posts: 214
08 Oct 2017 02:29 PM
Hello again people,

I'm trying to check when the player hits a brick (if the amount of points they have is 50 or over, it would remove one of then each second, as soon as the number hits to 0, the script deleting the value stops). Thanks again in advance.

Script:

local ringAmount = game.StarterGui.ScreenGui.Frame.RingAmount:FindFirstChild('Rings')
local ringValue = ringAmount:GetPropertyChangedSignal('Value')

-- Attempts to delete 1 from the ring value every second.
if (ringValue >= 50) then
spawn(function()
while (true) do
ringValue = (ringValue - 1)
wait(1)
end
end)
end

-- After the ring value hits 0, the last function removing one each time stops.
if (ringValue <= 0) then
spawn(function()
while (true) do
ringValue = (ringValue)
wait(1)
end
end)
end


- VIShark15
Report Abuse
annabet_h is not online. annabet_h
Joined: 13 Mar 2016
Total Posts: 1475
08 Oct 2017 02:34 PM
instead of using an if statement,

points=math.max(0,points-1)
Report Abuse
McRocketNuggets is not online. McRocketNuggets
Joined: 23 Nov 2016
Total Posts: 472
08 Oct 2017 02:35 PM
Q1: Why did you place the ring value inside of the client's playergui? It would be very easy for an exploiter to change that value to whatever they desire.

Q2: Are you trying to access the client's gui through a server script?

A: In order to find the client's side of the ring value, you wouldn't get into startergui but do something like this, game.Players[Player Name].PlayerGui
Report Abuse
Plutoeros is not online. Plutoeros
Joined: 13 Feb 2016
Total Posts: 214
08 Oct 2017 02:38 PM
A1: I don't even mind if they exploit it tbh, it's going to be a single player game anyway.

A2: I've tested in both Studio and ingame, neither work. The script is in a normal script within the block if you're wondering, so I assume it's a server script.

R: Wouldn't I have to restructure the whole value system to assign it to the playerGUI? It's this currently:

local ringAmount = script.Parent.RingAmount:FindFirstChild('Rings')
local ringText = script.Parent.RingAmount

if ringAmount and ringText then
ringAmount:GetPropertyChangedSignal('Value'):connect(function()
warn('Amount of rings:', ringAmount.Value)
ringText.Text = tostring(ringAmount.Value)
ringText.Background.Text = tostring(ringAmount.Value)
end)
end


- VIShark15
Report Abuse
Plutoeros is not online. Plutoeros
Joined: 13 Feb 2016
Total Posts: 214
08 Oct 2017 02:39 PM
Located in StarterGui like this:

StarterGui > ScreenGui > Frame > The script shown (within a local script)


- VIShark15
Report Abuse
ThanksRoBama is not online. ThanksRoBama
Joined: 21 May 2017
Total Posts: 127
08 Oct 2017 02:54 PM
GetPropertyChangedSignal doesn't return a number. When you do if (ringValue >= 50) then, you're comparing something that is not a number to a number. GetPropertyChangedSignal returns a RBXScriptSignal, which you can use like this:

function onRingValueChanged()
--This function is called every time the Value property of the ringAmount Instance changes, because it's connected to the Signal Instance at the end of this example:
end

ringAmount:GetPropertyChangedSignal("Value"):Connect(onRingValueChanged)

In Lua, Instances (and other things) are of the type "userdata". So that's why you got that particular error.
Report Abuse
McRocketNuggets is not online. McRocketNuggets
Joined: 23 Nov 2016
Total Posts: 472
08 Oct 2017 02:57 PM
Everything you place into startergui is placed in PlayerGui once the player respawns. Basically, you could create a server script that detects when the player touches the brick and fire an event to a local script that subtracts the ring's value.
--Example
--Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = Instance.new("RemoteEvent",ReplicatedStorage)
Event.Name = "TouchedEvent"
local function whenTouched(player)
Event:FireAllClients()
end
game.workspace.Part.Touched:Connect(whenTouched)
--Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("TouchedEvent")
local player = game.Players.LocalPlayer
local function whenFired()
if player.PlayerGui.ScreenGui.Frame.RingValue.Value >= 50 then
repeat player.PlayerGui.ScreenGui.Frame.RingValue.Value = player.PlayerGui.ScreenGui.Frame.RingValue.Value - 1 until player.PlayerGui.ScreenGui.Frame.RingValue.Value <= 0
end
end
Event.OnClientEvent:Connect(whenFired)
Report Abuse
Plutoeros is not online. Plutoeros
Joined: 13 Feb 2016
Total Posts: 214
08 Oct 2017 03:23 PM
Sorry if I sound dumb, but apparently 'Event' and 'whenFired' are unknown globals, would I need to reference the script within ServerScriptService in some way?

Event.OnClientEvent:Connect(whenFired)


- VIShark15
Report Abuse
ThanksRoBama is not online. ThanksRoBama
Joined: 21 May 2017
Total Posts: 127
08 Oct 2017 03:34 PM
whenFired would need to be the name of a variable holding a function. So:

function whenFired()

end

or whenFired = function()

end
Report Abuse
Plutoeros is not online. Plutoeros
Joined: 13 Feb 2016
Total Posts: 214
08 Oct 2017 03:35 PM
Oh nvm, it's just me being stupid and I put the end after the declaration of the eventchange, thanks for the help! :D


- VIShark15
Report Abuse
Plutoeros is not online. Plutoeros
Joined: 13 Feb 2016
Total Posts: 214
08 Oct 2017 03:42 PM
Oh RIP, now I'm getting this error:

21:#############orkspace.SuperSonicMonitor.SuperSonicMonitor.SPart.Script:44: attempt to index upvalue 'player' (a nil value).

I might as well just give you everything I have currently (located within a normal script within the brick, the Server script Nuggets supplied is in ServerScriptService).

*gulps*

local player = game.Players.LocalPlayer
local monitor = script.Parent.Parent
local sound = script.Parent.Parent.Parent.Sound
local moveScreen = script.Parent.Parent.Parent.BrokenMonitor.moveScreen
local speed = .01
local distance = 1.5
local timestorun = distance * 10
local supersound = script.Parent.Parent.Parent.SuperSonic
local ssound = game.Workspace.SpeedMonitor.Speed
local isound = game.Workspace.InvincibilityMonitor.Invincible
local lsound = game.Workspace.LifeMonitor.Life
local sssparkle = game.ServerStorage.SuperSonic

function onTouch(Part)
local check = Part.Parent
if check.Parent ~= nil then
monitor:Destroy()
sound:Play()
for i = 1, timestorun do
wait(speed)
moveScreen.Position = moveScreen.Position + Vector3.new(0,0.1,0)
end
end
moveScreen:Destroy()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("TouchedEvent")
local function whenFired()
if player.PlayerGui.ScreenGui.Frame.RingValue.Value >= 50 then
--##p##########local super = sssparkle:Clone()
super.Transparency = NumberSequence.new(0)
super.Parent = check.UpperTorso
supersound.Volume = 0.5
isound.Volume = 0
ssound.Volume = 0
lsound.Volume = 0
supersound:Play()
check.Humanoid.MaxHealth = math.huge
check.Humanoid.Health = math.huge
check.Humanoid.WalkSpeed = 150
end
repeat player.PlayerGui.ScreenGui.Frame.RingValue.Value = player.PlayerGui.ScreenGui.Frame.RingValue.Value - 1 until player.PlayerGui.ScreenGui.Frame.RingValue.Value <= 0
end
if player.PlayerGui.ScreenGui.Frame.RingValue.Value <= 0 then
supersound.Volume = 0
isound.Volume = 0.5
ssound.Volume = 0.5
lsound.Volume = 0.5
check.Humanoid.WalkSpeed = 75
check.Humanoid.MaxHealth = 100
check.Humanoid.Health = 100
end
Event.OnClientEvent:Connect(whenFired)
supersound:Stop()
end


script.Parent.Touched:connect(onTouch)



- VIShark15
Report Abuse
Plutoeros is not online. Plutoeros
Joined: 13 Feb 2016
Total Posts: 214
08 Oct 2017 03:44 PM
Line 44 = if player.PlayerGui.ScreenGui.Frame.RingValue.Value <= 0 then


- VIShark15
Report Abuse
McRocketNuggets is not online. McRocketNuggets
Joined: 23 Nov 2016
Total Posts: 472
08 Oct 2017 04:18 PM
Is that whole script in a server script? You can't "get" the local player inside of a server script.
Report Abuse
Plutoeros is not online. Plutoeros
Joined: 13 Feb 2016
Total Posts: 214
08 Oct 2017 04:21 PM
No, the content is within a normal script within the brick, THIS is within a script in ServerScriptService:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = Instance.new("RemoteEvent",ReplicatedStorage)
Event.Name = "TouchedEvent"
local function whenTouched(player)
Event:FireAllClients()
end

game.Workspace.SuperSonicMonitor.SuperSonicMonitor.SPart(whenTouched)


- VIShark15
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image