I'm currently working on getting this proximity prompt so when you click E on it, it'll change the number value on the UI system. I'm a little confused because when I set it all up it does not seem to be changing the number at all.
Code Connected to PP:
script.Parent.Triggered:Connect(function()
game.ServerStorage.genact.Value = game.ServerStorage.genact.Value + 1
end)
Code Connected to UI:
while true do
script.Parent.Text = ("Generators Activated: ")..game.ServerStorage.genact.Value
end
Any thoughts to fix this? I also have a intvalue inside the ServerStorage which these connect to, but it doesnt seem to change its value from 0
Your issue is that the while loop never yields. It loops endlessly until it times out.
A better solution is to use the Changed signal on your IntValue. You use it to update the text input when it changes.
local genact = game.ServerStorage.genact
local textBox = script.Parent
genact.Changed:Connect(function(newVal)
textBox.Text = "Generators Activated: " .. tostring(newVal)
end)
Related
could someone help me with this error?
I have a button created called "TextButton" and I have a text called "TextLabel", what I need to do is make the "TextLabel" increase by 1 when I press the "TextButton" button, could someone help me with this please.
function script.Parent.MouseButton1Click:Connect(function()
print("working..?..")
script.Parent.ValorVoto.Value = script.Parent.ValorVoto.Value+1
script.Parent.Parent.TextLabel = "clicks: "..script.Parent.ValorVoto.Value
end
script.Parent.Parent.TextButton.MouseButton1Down:Connect(clicking)
I think you've got a syntax error. It looks like you're defining a function, but also trying to connect that function immediately to the TextButton. Try naming your function clicking, and then passing that into the connection.
function clicking()
print("working..?..")
local vv = script.Parent.ValorVoto
vv.Value = vv.Value + 1
script.Parent.Parent.TextLabel.Text = "clicks: " .. tostring(vv.Value)
end
script.Parent.MouseButton1Click:Connect(clicking)
You have 2 errors in this script:
Line 4, add a .Text after referencing the TextLabel.
As Kylaa said, there is an error with line 7, you can just get rid of that line because your function was called with an event already. You don't need to recall that function, plus the function you're trying to call doesn't exist.
You don't mark it as a function if it's already listening for an event.
script.Parent.MouseButton1Click:Connect(function()
print("working..?..")
script.Parent.ValorVoto.Value = script.Parent.ValorVoto.Value+1
script.Parent.Parent.TextLabel.Text = "clicks: "..script.Parent.ValorVoto.Value
end
local Player = game.Players.LocalPlayer
local PlayerCash = Player:WaitForChild("leaderstats"):WaitForChild("Strength")
local Mouse = Player:GetMouse()
local amount = 50
script.Parent.Activate:Connect(function()
game.Players.LocalPlayer.leaderstats.money.Value = game.Players.LocalPlayer.leaderstats.money.Value + amount
end)
I am trying to make a code to give Strength when you click. When I press 'Play' it doesn't work. All it says in the output is
'attempt to index function with 'Connect'.'
The error "attempt to index [type] with [field name]" means that you are incorrectly using something like an object, and you are trying to access some field on it.
In your case, this error is pointing at the line : script.Parent.Activate:Connect.This says that script.Parent.Activate is a function and not a table, and you cannot call Connect on a function. This is just to help us figure out what is wrong with our code.
Since you working with Tools, there is a simple fix. Instead of using the Activate function, you are looking for the Activated event. So just change update that line like this :
script.Parent.Activated:Connect(function()
It connects a function to an event that happened, like this:
local tool = script.Parent
-- It connects the event (the tool being equipped) to a function.
tool.Equipped:Connect(function()
-- CODE
end)
Also, the answer above is how you can fix your problem and here's a shortcut: You have defined "Player" and you could've used it inside the function. Have a great day and God bless everyone here.
local garbage = game.Teams["Glizzy Garbage"]
local player = game.Players.LocalPlayer
if player.leaderstats.Pounds.Value <= 1000 then --this is the line that the output is detecting the error
player.Team = garbage
end
I am trying to make it where when the player reaches a certain amount of 'pounds' then they will automatically receive a roll. I've searched through many youtube videos and haven't found a fix or an alternative way to do this, and I'm not sure why this isn't working. This script is located in the workspace. All help is appreciated.
The LocalPlayer object is only exposed in LocalScripts. Because you're using a Script in the Workspace, you'll have to access the player object another way. It's also a good idea to handle this kind of logic inside a function that is fired any time the Pounds value changes.
Try using the game.Players.PlayerAdded signal :
local garbage = game.Teams["Glizzy Garbage"]
game.Players.PlayerAdded:Connect(function(player)
local Pounds = player.leaderstats.Pounds
Pounds.Changed:Connect(function(value)
if value <= 1000 then
player.Team = garbage
end
end)
end)
Mine is just
local plrStage = plr.leaderstats.Stage.Value
try instead of putting team name put team colour
also use
player.Team.Service = garbage
end)
I want to make a sort of Lobby system in Roblox Studio where if you have 4 people on a part you get sent to another place. I tried to set up a system for it, but it didn't work; can you help me through this?
I've tried making it so it says .Value at the end.
local TeleportService = game:GetService("TeleportService")
player_amount = script.Parent.Parent.Parent.Player_Count
local placeID_1 = 4119652438
local function onPartTouch(otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
player_amount.Value = player_amount.Value + 1
end
if player_amount == 4 then
TeleportService:Teleport(placeID_1, player)
end
end
script.Parent.Touched:Connect(onPartTouch)
I expected the output to be 0 then if one person steps on it, it would update the sign to say 1. But it only stays at 0.
This is not a viable solution as .Touched fires every frame the player touches a part, and only when they move. I suggest creating a hitbox, as I have done here
I'm pretty new to ROBLOX development and don't really know how to make the objects talk just yet.
I have 16 cells all with an individual open and close button. Those work. I want to create a button that will open all doors at once.
function onClicked()
script.Parent.Parent.Door.Transparency = 1
script.Parent.Parent.Door.CanCollide= false
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
The above function is on each cell and works. I would like to loop through each one and fire it when I click a different button. I've been looking into getting each object with the same names but haven't been able to iterate through it.
The below code is my attempt to get it to fire off each one!
local part = workspace.OpenButton
local clickDetector = Instance.new("ClickDetector")
local function onMouseClick(player)
for _, child in pairs(workspace.PrisonCell:GetChildren()) do
print(child)
child:connect(child.Door.onClicked)
end
end
clickDetector.Parent = part
part.Parent = workspace
clickDetector.MouseClick:connect(onMouseClick)
Any help with this would be greatly appreciated!
You could do something similar to this to open all of the prison doors at once:
local part = workspace.OpenButton
local clickDetector = Instance.new("ClickDetector")
local function onMouseClick(player)
for _, child in pairs(workspace.PrisonCell:GetChildren()) do
child.Door.Transparency = 1
child.Door.CanCollide = false
end
end
clickDetector.Parent = part
part.Parent = workspace
clickDetector.MouseClick:connect(onMouseClick)
The downside to using the solution above is that if you want to change the door opening script, you would have to change it in both the individual cell buttons as well as this master button script. If you think this might be a problem in the future, I would consider writing a master script somewhere in ServerScriptService that uses BindableEvents for communcation with the button clicking scripts in order to keep the door opening function in one place.