Roblox Studio Error: Expected ')' (to close '(' at column 18), got '=' - roblox

I am trying to make a door move to a new position using the tween service. The problem is that I keep getting the error, Expected ')' (to close '(' at column 18), got '=', and I don't know why. It highlights the "=" next to "Position" on line 21 in red.
local service = game:GetService("TweenService")
local cupboard1 = game.Workspace.Door1
local cupboard2 = game.Workspace.Door2
local cupboard3 = game.Workspace.Door3
local cupboard4 = game.Workspace.Door4
local handle1 = game.Workspace.Handle1
local handle2 = game.Workspace.Handle2
local handle3 = game.Workspace.Handle3
local handle4 = game.Workspace.Handle4
local info = TweenInfo.new(2)
if state == true then
game.Workspace.Handle1.ClickDetector.MouseClick:connect(function()
local state = false
local change = (Position = Vector3.new(61.831, 4.997, 68.415)) -- door
local change1 = (Position = Vector3.new(63.401, 5.416, 67.89)) -- handle
local change2 = (Orientation = Vector3.new(0, 90, 0)) -- handle
local change3 = (Orientation = Vector3.new(0, 90, 0)) -- door
local tween = service:Create(cupboard1, info, change)
tween:Play()
local tween1 = service:Create(handle1, info, change1)
tween1:Play()
local tween2 = service:Create(handle1, info, change2)
tween2:Play()
local tween3 = service:Create(cupboard1, info, change3)
tween3:Play()
end)
end
if state == false then
game.Workspace.Handle1.ClickDetector.MouseClick:connect(function()
local state = true
local change = (Position = Vector3.new(58.112, 4.997, 66.588)) -- door
local change1 = (Position = Vector3.new(56.631, 5.416, 65.849)) -- handle
local change2 = (Orientation = Vector3.new(0, -135, 0)) -- handle
local change3 = (Orientation = Vector3.new(0, -135, 0)) -- door
local tween = service:Create(cupboard1, info, change)
tween:Play()
local tween1 = service:Create(handle1, info, change1)
tween1:Play()
local tween2 = service:Create(handle1, info, change2)
tween2:Play()
local tween3 = service:Create(cupboard1, info, change3)
tween3:Play()
end)
end
I've tried changing "=" to "==" but it gives me a warning saying Position and Orientation isn't defined.

You are trying to pass a table of changes into your tween. But when you use parenthesis, it is trying to evaluate the line, and this isn't valid lua.
Try changing your parentheses to curly brackets. This will properly assign the changes as a table, which you can pass to your tweens.
local change = { Position = Vector3.new(58.112, 4.997, 66.588)} -- door
local tween = service:Create(cupboard1, info, change)

Related

ServerScriptService.Size:4: attempt to index nil with 'Humanoid'

Cant figure out what the problem is
while wait(.5) do
local children = game.Players:GetChildren("Humanoid")
for i = 1, #children do
local hum = children[i] .Character.Humanoid
hum.HeadScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.BodyHeightScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.BodyWidthScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.BodyDepthScale.Value = children[i].leaderstats.Points.Value/50 +1
hum.WalkSpeed = children[i].leaderstats.Points.Value/3.12
hum.JumpPower = children[i].leaderstats.Points.Value
hum.MaxHealth = children[i].leaderstats.Points.Value+25
end
end
was trying to get a simple size script to work.
The attempt to index nil with Humanoid error is telling you that the object that you are trying to grab the Humanoid out of doesn't exist. This line specifically :
local hum = children[i].Character.Humanoid
When a player joins the game, there is an indeterminate amount of time before their character model actually spawns into the world. So between when they join and when their character spawns, the Player.Character property is nil.
Your code does not handle the possibility that the character model is nil, and you are trying to access the humanoid immediately.
A safer approach is not to use a loop, but to observe changes to the leaderstats values and react to those changes. So in your code that creates your leaderstats objects, do something like this :
local Players = game:GetService("Players")
local function updateCharacter(hum : Humanoid, points : number)
local bodyScale = (points / 50) + 1
local walkSpeed = points / 3.12
local jump = points
local health = points + 25
hum.HeadScale.Value = bodyScale
hum.BodyHeightScale.Value = bodyScale
hum.BodyWidthScale.Value = bodyScale
hum.BodyDepthScale.Value = bodyScale
hum.WalkSpeed = walkSpeed
hum.JumpPower = jump
hum.MaxHealth = health
end
Players.PlayerAdded:Connect(function(player)
-- when a player joins the game, give them a leaderstats folder
local leaderstatsFolder = Instance.new("Folder")
leaderstatsFolder.Name = "leaderstats"
local pointsValue = Instance.new("IntValue", leaderstats)
pointsValue.Name = "Points"
pointsValue.Value = 0 -- or load from dataStores
leaderstatsFolder.Parent = player
-- listen for changes to the points and resize the character
pointsValue.Changed:Connect(function(newValue)
-- escape if the character doesn't exist
local character = player.Character
if character then
updateCharacter(character.Humanoid, newValue)
end
end)
-- when the character model spawns into the world, update it immediately with the player's point size
player.CharacterAdded:Connect(function(character)
updateCharacter(character.Humanoid, pointsValue.Value)
end)
end)

Character doesn't immediatley go to the correct height when changing hipheight

For some reason, when I change a characters hipheight in roblox studio, they are a bit taller than they should be for a bit, then settle down to normal. Here is the code for my hipheight changing script:
--// Configuration
local keybind = "C"
local animationId = 11144547033 --> Replace the number with your animation ID!
--// Variables
local UserInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local hip = humanoid.HipHeight
local animation = Instance.new("Animation")
animation.AnimationId = 'rbxassetid://' .. animationId
local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
animationTrack.Priority = Enum.AnimationPriority.Action
local crouching = false
--// Functions
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode[keybind] then
if crouching then
humanoid.WalkSpeed = 16
crouching = false
animationTrack:Stop()
character.HumanoidRootPart.CanCollide = true
humanoid.HipHeight = hip
else
humanoid.WalkSpeed = 7
humanoid.HipHeight = 1.5
crouching = true
animationTrack:Play()
end
end
end)
, and what happens
YT Vid

Boat Spawn (Roblox Studio)

I'm trying(I'm very new) to make a game where you have to attack each other with a boat. There is a button on each island and when you press it, a boat should appear. (this works so far)
But as soon as you want to spawn a new boat it removes everyones boat. I thought it makes sense to use player.id but this still won't work. Does anyone know the solution?
Below you will find the code thats hidden in a part.
Thanks!
CODE:
local cd = script.Parent.ClickDetector
local boat = script.Parent.Parent.Firstboat
local button = script.Parent
local debounce = false
game.Players.PlayerAdded:Connect(function(player)
print(player.UserId)
local plruserid = player.UserId
print(player.Name)
boat.Parent = game.ServerStorage
cd.MouseHoverEnter:Connect(function()
button.Transparency = 0.5
end)
cd.MouseHoverLeave:Connect(function()
button.Transparency = 0
end)
cd.MouseClick:Connect(function()
local SetNameToBoat = plruserid
print (SetNameToBoat)
local oldboat = workspace:FindFirstChild(SetNameToBoat)
if not debounce then
if oldboat then
oldboat : destroy()
end
debounce = true
local NewBoat = boat:clone()
NewBoat.Name = (SetNameToBoat)
NewBoat.Parent = game.Workspace
wait(5)
debounce = false
end
end)
end)
I simplified the code and found the solution:
local cd = workspace.Button:WaitForChild('ClickDetector')
local boat = game:GetService('ServerStorage'):WaitForChild('Boat')
local button = workspace:WaitForChild('Button')
local debounce = false
cd.MouseHoverEnter:Connect(function()
button.Transparency = 0.5
end)
cd.MouseHoverLeave:Connect(function()
button.Transparency = 0
end)
cd.MouseClick:Connect(function(player)
local plruserid = player.UserId
local SetNameToBoat = plruserid
print(SetNameToBoat)
local oldboat = workspace:FindFirstChild(SetNameToBoat)
if not debounce then
if oldboat then
oldboat:destroy()
end
debounce = true
local NewBoat = boat:clone()
NewBoat.Name = SetNameToBoat
NewBoat.Parent = game.Workspace
wait(5)
debounce = false
end
end)

Roblox Studio how to make that when the part size reached a specyific number it will do something

local code = game.Workspace.Script
local basep = game.Workspace.Baseplate
local sp = true
while sp == true do
basep.Size = Vector3.new(basep.Size.X - 2,basep.Size.Y,basep.Size.Z - 2)
wait(0.5)
print(basep.Size)
end
if basep.Size == Vector3.new(10, 5, 10) then
print("worked")
end
the last part isn't working, i don't know how to put that when it reaches the size X-10 Y-5 Y-10 then it stops (i put print("worked") so I can see if it is working)
you would put the if block inside your endless loop, like so:
while sp == true do
basep.Size = Vector3.new(basep.Size.X - 2,basep.Size.Y,basep.Size.Z - 2)
print(basep.Size)
if basep.Size == Vector3.new(10, 5, 10) then
print("worked")
break -- <=== add this if you want to break out of the loop
end
wait(0.5)
end
Alternatively, you can use a Tween to handle the animation, then attach a callback for when the animation ends.
local TweenService = game:GetService("TweenService")
-- choose an Instance to change
local basep = game.Workspace.Baseplate
-- create a list of properties to change during the animation
local goal = {
Size = Vector3.new(10, 5, 10)
}
-- configure how the animation will work
local timeToComplete = 5 --seconds
local timeToDelay = 0 -- seconds
local tweenInfo = TweenInfo.new(timeToComplete, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, timeToDelay)
-- create the animation and attach a listener for when the animation finishes
local tween = TweenService:Create(basep, tweenInfo, goal)
tween.Completed:Connect(function()
print("worked")
end)
tween:Play()

How do I change a value in the leaderstats via touching a part? (Roblox)

Here's the error and what I've tried.
Error: Workspace.Part.Script:4: attempt to index nil with 'leaderstats'
My code:
Making Leaderstats:
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Model")
ls.Name = "leaderstats"
ls.Parent = plr
local m = Instance.new("IntValue")
m.Name = "Stars"
m.Value = 0
m.Parent = ls
end)
Touch Code:
local collected = false
script.Parent.Touched:Connect(function()
if collected == false then
game.Players.LocalPlayer.leaderstats.Stars.Value = game.Players.LocalPlayer.leaderstats.Stars.Value + 1
end
collected = true
end)
A server script would suit your need better. In a localscript, the change would only appear for the player. Also, it's better practice to use the Players service offered by Roblox. Here's an example:
local Players = game:GetService('Players')
local collected = false
script.Parent.Touched:Connect(function(partTouched)
if partTouched.Parent:IsA('Model') and partTouched.Parent:FindFirstChild('Humanoid') and partTouched:IsA('BasePart') then -- Is this a player? If so, then..
local player = Players:GetPlayerFromCharacter(partTouched.Parent)
if collected == false then
player.leaderstats.Stars.Value += 1 -- shorter syntax
end
collected = true
--script.Parent:Destroy() optional if this part won't be used again.
end
end)
If you're planning to use this for many parts, using a central ModuleScript would save you lots of changing things back and forth: https://developer.roblox.com/en-us/api-reference/class/ModuleScript