Tween Service on GUI not working correctly - lua

I tried to make a code that if a RemoteEvent fire on Server, then the same RemoteEvent fires the client. When a local script receives the RemoteEvent FireClient then the Tween starts but this isn't occurring. The Frame don't turns Visible too. The output don't return any error. How i can fix that?
Code below:
local framground = script.Parent.Frame.GroundSmash.GroundSmash
local punch = script.Parent.Frame.EtoPunch.PunchRecharge
local TweenS = game:GetService("TweenService")
local TweenInf = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local Tweenin = TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local Tween = TweenS:Create(framground, TweenInf, {Size = UDim2.new(0,1, 0, 67)})
local TweenC = TweenS:Create(punch, Tweenin, {Size = UDim2.new(0,1, 0, 67)})
game.ReplicatedStorage.CombatSkills.GroundSmash.OnClientEvent:Connect(function()
framground.Visible = true
Tween:Play()
task.wait(5)
framground.Size = UDim2.new(0, 238, 0, 67)
framground.Visible = false
end)
game.ReplicatedStorage.CombatSkills.Combat.OnClientEvent:Connect(function()
punch.Visible = true
TweenC:Play()
task.wait(.5)
punch.Size = UDim2.new(0, 238, 0, 67)
punch.Visible = false
end)

Related

Roblox GUI Kill Brick

I'm learning LUA and trying to make a GUI that spawns a brick above the players head which kills the player if touched. I'm not sure how to to connect the Touched event to a part that's spawned in with Instance.new? Here's what I got so far!
local button = script.Parent
local function kill()
button.BackgroundColor3 = Color3.fromRGB(255, 0, 4)
button.parent.BackgroundColor3 = Color3.fromRGB(255, 0, 4)
local player = game.Players.LocalPlayer.character
local killBrick = Instance.new("Part")
killBrick.Name = "Kill Brick"
killBrick.CFrame = player.Head.CFrame*CFrame.new(0,10,0)
killBrick.Parent = game.Workspace
killBrick.Color = Color3.fromRGB(255, 0, 0)
killBrick.Material = "Neon"
killBrick.BottomSurface = "Smooth"
killBrick.TopSurface = "Studs"
button.BackgroundColor3 = Color3.fromRGB(80, 80, 255)
button.parent.BackgroundColor3 = Color3.fromRGB(106, 146, 255)
end
button.MouseButton1Click:Connect(kill)
I fixed it by doing:
killBrick.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid.Health=0
end
end)

How to make the gui button click and give prompt for product purchase?

The script is very messy due to multiple attempts of trying to fix it from various places and people, yet it led to square one each time...
Local script:
local Cash500 = script.Parent
local A500 = script.Parent.A500
local player = game.Players.LocalPlayer ReplicatedStorage = game:GetService("ReplicatedStorage")
MPS = game:GetService("MarketplaceService")
id = 3736929511
local player = game.Players.LocalPlayer
local remoteEvent = ReplicatedStorage:WaitForChild("RE500")
--Enlarges size when mouse hovers
script.Parent.MouseEnter:Connect(function(x, y)
Cash500.Size = UDim2.new (0, 90, 0, 85)
A500.Size = UDim2.new(0, 75, 0, 30)
end)
--Resets size on not hovering mouse after mouse hovered
script.Parent.MouseLeave:Connect(function(x, y)
Cash500.Size = UDim2.new (0, 75, 0, 70)
A500.Size = UDim2.new(0, 60, 0, 15)
end)
--Purchase 500 money for 35 robux
--Fires remoteEvent when clicked- goes to RemoteEventController that gives money over
Cash500.MouseButton1Click:Connect(function()
MPS:PromptProductPurchase(player, id)
remoteEvent:FireServer("RE500")
end)
Leaderstat Handler:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Money = Instance.new("IntValue", leaderstats)
Money.Name = "Money"
local Gems = Instance.new("IntValue", leaderstats)
Gems.Name = "Gems"
end)
local function addTime(player)
while true do
local RandomNumber = math.random(1,5)
wait(3)
player.leaderstats.Money.Value+=RandomNumber -- Same as Value=value+1 it is now- Value+=1
end
end
game.Players.PlayerAdded:Connect(addTime)
RemoteEvent Controller:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MPS = game:GetService("MarketplaceService")
local remoteEvent = ReplicatedStorage:WaitForChild("RE500")
local function Additional500(player)
print(player.Name .. " fired the remote event")
print("Updated! <3")
end
MPS.ProcessReceipt = function(receiptInfo)
print("OOOF")
if receiptInfo.ProductId == 3736929511 then
print("Start!")
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Money.Value = player.leaderstats.Money.Value + 500
print("Ended!")
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
remoteEvent.OnServerEvent:Connect(Additional500)
There are no error messages coming out of the output but this when you click it comes up:
The Error message
Anyone know what to do ? Thanks! :)

How to trigger a function after tweening in ROBLOX

Does anybody know how to trigger a function call after tweening? I want to show some text after the tween stops.
Tweens come with a Completed event, and you can attach a callback to it.
In a LocalScript, you can have something like this :
local TweenService = game:GetService("TweenService")
-- find your GUI element to animate
local lp = game.Players.LocalPlayer
local exampleScreen = Instance.new("ScreenGui", lp.PlayerGui)
exampleScreen.Name = "Example"
local label = Instance.new("TextLabel")
label.Position = UDim2.new(0,0,0,0)
label.Size = UDim2.new(0, 10, 0, 10)
label.Parent = exampleScreen
-- choose some properties to animate
local goal = {}
goal.Position = UDim2.new(0.5, -20, 0.5, -100)
goal.Size = UDim2.new(0.5, 40, 0.5, 200)
-- create the tween
local time = 5 --seconds
local tweenInfo = TweenInfo.new(time)
local tween = TweenService:Create(label, tweenInfo, goal)
-- listen for when the tween is finished
tween.Completed:Connect( function(tweenState)
label.Text = "Tween Completed"
end)
-- play the tween
tween:Play()
You have to set the tween time in tweeninfo variable. Just make it wait() for the same time as the tween takes to play() and then trigger a function.

How do you move a part to the player's torso using an offset?

I've tried switching from Vector3 to CFrame and it still hasn't been working. The best I've gotten is the part appearing like 10 feat in the air, this is what I have so far.
local Dog = game:GetService("ReplicatedStorage"):WaitForChild("PetTesting")
local RunService = game:GetService("RunService")
local tweenService = game:GetService("TweenService")
local Petfollow = game:GetService("ReplicatedStorage"):WaitForChild("PetFollow")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
wait(1)
local dc = Dog:Clone()
dc.Name = "Pet"
dc.Parent = char
local offsetCframe = CFrame.new(0, 0, 0)
dc.CFrame = char:WaitForChild("HumanoidRootPart").CFrame + offsetCframe
dc.Anchored = true
dc.CanCollide = false
dc.Transparency = 0
end)
end)
You can use a bit of CFrame manipulation as described in https://developer.roblox.com/en-us/api-reference/datatype/CFrame. I am not sure if this is the right way of doing this, so please reply if this is incorrect.
local offset = Vector3.new(0, 0, 10)
local newCFrame = humanoidRootPart.CFrame * offset

"The function Create is not a member of "UnionOperation" when trying to use the TweenService()

I am trying to create a Maze Runner game. When making the doors to open and close i scripted it using ROBLOX's built in tween service. I run and i get "The function Create is not a member of "UnionOperation"" I have never heard of this error and couldn't find a solution. I am trying to do this on a Union part. I have no idea what to do. I need the tween to work as expected (tween the part a few spaces).
TweenService = game:GetService("TweenService")
Door = script.Parent.Door2
Door1 = Door:WaitForChild("Door1")
Door2 = Door:WaitForChild("Door2")
local TweenInformationIn = TweenInfo.new(
6,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0
)
local Door1Open = {CFrame = CFrame.new(1226.993, 131.187, -769.185)}
local Door2Open = {CFrame = CFrame.new(1226.993, 131.187, -814.271)}
local Door1Close = {CFrame = CFrame.new(1226.993, 131.187, -749.831)}
local Door2Close = {CFrame = CFrame.new(1226.993, 131.187, -834.331)}
local Tween1Open = TweenService.Create(Door1, TweenInformationIn, Door1Open)
local Tween2Open = TweenService.Create(Door2, TweenInformationIn,Door2Open)
local TweenClose = TweenService.Create(Door1, TweenInformationIn, Door1Close)
local Tween2Close = TweenService.Create(Door2,TweenInformationIn,Door2Close)
Tween1Open:Play()
Tween2Open:Play()
Replace TweenService.Create with TweenService:Create
TweenService:Create(Door1, TweenInformationIn, Door1Open)
is equivalent to
TweenService.Create(TweenService, Door1, TweenInformationIn, Door1Open)
whereas you called
TweenService.Create(Door1, TweenInformationIn, Door1Open)
So inside TweenService.Create things went south because Door1 was where TweenService should have been.
There is actually a code sample in the Robolox manual that shows how to use TweenService.
https://developer.roblox.com/api-reference/function/TweenService/Create
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = game.Workspace
local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
true, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tween = TweenService:Create(part, tweenInfo, {Position = Vector3.new(0, 30, 0)})
tween:Play()
wait(10)
tween:Cancel() -- cancel the animation after 10 seconds

Resources